Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move component basics section #39

Merged
merged 22 commits into from
Jan 28, 2020
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"semi": false,
"singleQuote": true
}
14 changes: 14 additions & 0 deletions src/.vuepress/components/alert-box.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<template>
<div class="demo-alert-box">
<strong>Error!</strong>
<slot></slot>
</div>
</template>

<style scoped>
.demo-alert-box {
padding: 10px 20px;
background: #f3beb8;
border: 1px solid #f09898;
}
</style>
9 changes: 9 additions & 0 deletions src/.vuepress/components/blog-post1.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<template>
<h3>{{ title }}</h3>
</template>

<script>
export default {
props: ['title']
}
</script>
14 changes: 14 additions & 0 deletions src/.vuepress/components/blog-post2.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<template>
<div>
<h4>{{ title }}</h4>
<button @click="$emit('enlarge-text')">
Enlarge text
</button>
</div>
</template>

<script>
export default {
props: ['title']
}
</script>
15 changes: 15 additions & 0 deletions src/.vuepress/components/button-counter.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<template>
<button v-on:click="count++">You clicked me {{ count }} times.</button>
</template>

<script>
export default {
data() {
return {
count: 0
}
}
}
</script>

<style lang="scss" scoped></style>
5 changes: 5 additions & 0 deletions src/.vuepress/components/components-1.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<template>
<div id="components-demo" class="demo">
<button-counter></button-counter>
</div>
</template>
7 changes: 7 additions & 0 deletions src/.vuepress/components/components-2.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<template>
<div id="components-demo2" class="demo">
<button-counter></button-counter>
<button-counter></button-counter>
<button-counter></button-counter>
</div>
</template>
7 changes: 7 additions & 0 deletions src/.vuepress/components/components-3.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<template>
<div id="blog-post-demo" class="demo">
<blog-post1 title="My journey with Vue"></blog-post1>
<blog-post1 title="Blogging with Vue"></blog-post1>
<blog-post1 title="Why Vue is so fun"></blog-post1>
</div>
</template>
27 changes: 27 additions & 0 deletions src/.vuepress/components/components-4.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<template>
<div id="blog-posts-events-demo" class="demo">
<div :style="{ fontSize: postFontSize + 'em' }">
<blog-post2
v-for="post in posts"
v-bind:key="post.id"
v-bind:title="post.title"
v-on:enlarge-text="postFontSize += 0.1"
></blog-post2>
</div>
</div>
</template>

<script>
export default {
data() {
return {
posts: [
{ id: 1, title: 'My journey with Vue', content: '...content...' },
{ id: 2, title: 'Blogging with Vue', content: '...content...' },
{ id: 3, title: 'Why Vue is so fun', content: '...content...' }
],
postFontSize: 1
}
}
}
</script>
13 changes: 13 additions & 0 deletions src/.vuepress/components/components-5.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<template>
<div id="slots-demo" class="demo">
<alert-box>
Something bad happened.
</alert-box>
</div>
</template>

<script>
export default {}
</script>

<style lang="scss" scoped></style>
58 changes: 58 additions & 0 deletions src/.vuepress/components/components-6.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<template>
<div id="dynamic-component-demo" class="demo">
<button
v-for="tab in tabs"
v-bind:key="tab"
class="dynamic-component-demo-tab-button"
v-bind:class="{
'dynamic-component-demo-tab-button-active': tab === currentTab
}"
v-on:click="currentTab = tab"
>
{{ tab }}
</button>
<component
v-bind:is="currentTabComponent"
class="dynamic-component-demo-tab"
></component>
</div>
</template>

<script>
export default {
data() {
return {
currentTab: 'Home',
tabs: ['Home', 'Posts', 'Archive']
}
},
computed: {
currentTabComponent() {
return `tab-${this.currentTab.toLowerCase()}`
}
}
}
</script>

<style scoped>
.dynamic-component-demo-tab-button {
padding: 6px 10px;
border-top-left-radius: 3px;
border-top-right-radius: 3px;
border: 1px solid #ccc;
cursor: pointer;
background: #f0f0f0;
margin-bottom: -1px;
margin-right: -1px;
}
.dynamic-component-demo-tab-button:hover {
background: #e0e0e0;
}
.dynamic-component-demo-tab-button-active {
background: #e0e0e0;
}
.dynamic-component-demo-tab {
border: 1px solid #ccc;
padding: 10px;
}
</style>
3 changes: 3 additions & 0 deletions src/.vuepress/components/tab-archive.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<template>
<div>Archive component</div>
</template>
3 changes: 3 additions & 0 deletions src/.vuepress/components/tab-home.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<template>
<div>Home component</div>
</template>
3 changes: 3 additions & 0 deletions src/.vuepress/components/tab-posts.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<template>
<div>Posts component</div>
</template>
3 changes: 2 additions & 1 deletion src/.vuepress/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ module.exports = {
'conditional',
'list',
'events',
'forms'
'forms',
'component-basics',
]
}
]
Expand Down
Loading