Skip to content

Commit 94e1724

Browse files
Move component basics section (#39)
* feat: started component basics * feat: add button-counter example * feat: moved component props * feat: reworked events on components * Added v-model on components * feat: added slots to components basic * feat: added dynamic components * fix: fixed config * fix: replaced fiddles with codesandboxes * Update src/guide/component-basics.md Co-Authored-By: Rahul Kadyan <[email protected]> * fix: removed new Vue reminiscenses * fix: fixed createApp reference * fix: fixed update events names * fix: fixed createApp * fix: changed modelValue to be camelCase * fix: fixed prop name * Update src/guide/component-basics.md Co-Authored-By: Rahul Kadyan <[email protected]> * Update src/guide/component-basics.md Co-Authored-By: Rahul Kadyan <[email protected]> * feat: added a note on case-insensitiveness Co-authored-by: Rahul Kadyan <[email protected]>
1 parent b64f3b5 commit 94e1724

16 files changed

+593
-2
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<template>
2+
<div class="demo-alert-box">
3+
<strong>Error!</strong>
4+
<slot></slot>
5+
</div>
6+
</template>
7+
8+
<style scoped>
9+
.demo-alert-box {
10+
padding: 10px 20px;
11+
background: #f3beb8;
12+
border: 1px solid #f09898;
13+
}
14+
</style>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<template>
2+
<h3>{{ title }}</h3>
3+
</template>
4+
5+
<script>
6+
export default {
7+
props: ['title']
8+
}
9+
</script>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<template>
2+
<div>
3+
<h4>{{ title }}</h4>
4+
<button @click="$emit('enlarge-text')">
5+
Enlarge text
6+
</button>
7+
</div>
8+
</template>
9+
10+
<script>
11+
export default {
12+
props: ['title']
13+
}
14+
</script>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<template>
2+
<button v-on:click="count++">You clicked me {{ count }} times.</button>
3+
</template>
4+
5+
<script>
6+
export default {
7+
data() {
8+
return {
9+
count: 0
10+
}
11+
}
12+
}
13+
</script>
14+
15+
<style lang="scss" scoped></style>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<template>
2+
<div id="components-demo" class="demo">
3+
<button-counter></button-counter>
4+
</div>
5+
</template>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<template>
2+
<div id="components-demo2" class="demo">
3+
<button-counter></button-counter>
4+
<button-counter></button-counter>
5+
<button-counter></button-counter>
6+
</div>
7+
</template>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<template>
2+
<div id="blog-post-demo" class="demo">
3+
<blog-post1 title="My journey with Vue"></blog-post1>
4+
<blog-post1 title="Blogging with Vue"></blog-post1>
5+
<blog-post1 title="Why Vue is so fun"></blog-post1>
6+
</div>
7+
</template>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<template>
2+
<div id="blog-posts-events-demo" class="demo">
3+
<div :style="{ fontSize: postFontSize + 'em' }">
4+
<blog-post2
5+
v-for="post in posts"
6+
v-bind:key="post.id"
7+
v-bind:title="post.title"
8+
v-on:enlarge-text="postFontSize += 0.1"
9+
></blog-post2>
10+
</div>
11+
</div>
12+
</template>
13+
14+
<script>
15+
export default {
16+
data() {
17+
return {
18+
posts: [
19+
{ id: 1, title: 'My journey with Vue', content: '...content...' },
20+
{ id: 2, title: 'Blogging with Vue', content: '...content...' },
21+
{ id: 3, title: 'Why Vue is so fun', content: '...content...' }
22+
],
23+
postFontSize: 1
24+
}
25+
}
26+
}
27+
</script>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<template>
2+
<div id="slots-demo" class="demo">
3+
<alert-box>
4+
Something bad happened.
5+
</alert-box>
6+
</div>
7+
</template>
8+
9+
<script>
10+
export default {}
11+
</script>
12+
13+
<style lang="scss" scoped></style>
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<template>
2+
<div id="dynamic-component-demo" class="demo">
3+
<button
4+
v-for="tab in tabs"
5+
v-bind:key="tab"
6+
class="dynamic-component-demo-tab-button"
7+
v-bind:class="{
8+
'dynamic-component-demo-tab-button-active': tab === currentTab
9+
}"
10+
v-on:click="currentTab = tab"
11+
>
12+
{{ tab }}
13+
</button>
14+
<component
15+
v-bind:is="currentTabComponent"
16+
class="dynamic-component-demo-tab"
17+
></component>
18+
</div>
19+
</template>
20+
21+
<script>
22+
export default {
23+
data() {
24+
return {
25+
currentTab: 'Home',
26+
tabs: ['Home', 'Posts', 'Archive']
27+
}
28+
},
29+
computed: {
30+
currentTabComponent() {
31+
return `tab-${this.currentTab.toLowerCase()}`
32+
}
33+
}
34+
}
35+
</script>
36+
37+
<style scoped>
38+
.dynamic-component-demo-tab-button {
39+
padding: 6px 10px;
40+
border-top-left-radius: 3px;
41+
border-top-right-radius: 3px;
42+
border: 1px solid #ccc;
43+
cursor: pointer;
44+
background: #f0f0f0;
45+
margin-bottom: -1px;
46+
margin-right: -1px;
47+
}
48+
.dynamic-component-demo-tab-button:hover {
49+
background: #e0e0e0;
50+
}
51+
.dynamic-component-demo-tab-button-active {
52+
background: #e0e0e0;
53+
}
54+
.dynamic-component-demo-tab {
55+
border: 1px solid #ccc;
56+
padding: 10px;
57+
}
58+
</style>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<template>
2+
<div>Archive component</div>
3+
</template>

src/.vuepress/components/tab-home.vue

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<template>
2+
<div>Home component</div>
3+
</template>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<template>
2+
<div>Posts component</div>
3+
</template>

src/.vuepress/config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ module.exports = {
3939
'conditional',
4040
'list',
4141
'events',
42-
'forms'
42+
'forms',
43+
'component-basics',
4344
]
4445
}
4546
]

0 commit comments

Comments
 (0)