Skip to content

Commit 7d2ef76

Browse files
ntepluhinaNataliaTepluhina
ntepluhina
authored andcommitted
Added dynamic components
1 parent 3249d59 commit 7d2ef76

File tree

5 files changed

+384
-27
lines changed

5 files changed

+384
-27
lines changed
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
<template>
2+
<div id="dynamic-component-demo" class="demo">
3+
<button
4+
v-for="tab in tabs"
5+
v-bind:key="tab"
6+
v-bind:class="[
7+
'dynamic-component-demo-tab-button',
8+
{ 'dynamic-component-demo-active': currentTab === tab }
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+
import TabPosts from './tab-posts-dynamic'
23+
import TabArchive from './tab-archive'
24+
export default {
25+
components: {
26+
TabPosts,
27+
TabArchive
28+
},
29+
data() {
30+
return {
31+
currentTab: 'Posts',
32+
tabs: ['Posts', 'Archive']
33+
}
34+
},
35+
computed: {
36+
currentTabComponent() {
37+
return 'tab-' + this.currentTab.toLowerCase()
38+
}
39+
}
40+
}
41+
</script>
42+
43+
<style>
44+
.dynamic-component-demo-tab-button {
45+
padding: 6px 10px;
46+
border-top-left-radius: 3px;
47+
border-top-right-radius: 3px;
48+
border: 1px solid #ccc;
49+
cursor: pointer;
50+
background: #f0f0f0;
51+
margin-bottom: -1px;
52+
margin-right: -1px;
53+
}
54+
.dynamic-component-demo-tab-button:hover {
55+
background: #e0e0e0;
56+
}
57+
.dynamic-component-demo-tab-button.dynamic-component-demo-active {
58+
background: #e0e0e0;
59+
}
60+
.dynamic-component-demo-tab {
61+
border: 1px solid #ccc;
62+
padding: 10px;
63+
}
64+
.dynamic-component-demo-posts-tab {
65+
display: flex;
66+
}
67+
.dynamic-component-demo-posts-sidebar {
68+
max-width: 40vw;
69+
margin: 0 !important;
70+
padding: 0 10px 0 0 !important;
71+
list-style-type: none;
72+
border-right: 1px solid #ccc;
73+
}
74+
.dynamic-component-demo-posts-sidebar li {
75+
white-space: nowrap;
76+
text-overflow: ellipsis;
77+
overflow: hidden;
78+
cursor: pointer;
79+
}
80+
.dynamic-component-demo-posts-sidebar li:hover {
81+
background: #eee;
82+
}
83+
.dynamic-component-demo-posts-sidebar li.dynamic-component-demo-active {
84+
background: lightblue;
85+
}
86+
.dynamic-component-demo-post-container {
87+
padding-left: 10px;
88+
}
89+
.dynamic-component-demo-post > :first-child {
90+
margin-top: 0 !important;
91+
padding-top: 0 !important;
92+
}
93+
</style>
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
<template>
2+
<div id="dynamic-component-demo" class="demo">
3+
<button
4+
v-for="tab in tabs"
5+
v-bind:key="tab"
6+
v-bind:class="[
7+
'dynamic-component-demo-tab-button',
8+
{ 'dynamic-component-demo-active': currentTab === tab }
9+
]"
10+
v-on:click="currentTab = tab"
11+
>
12+
{{ tab }}
13+
</button>
14+
<keep-alive>
15+
<component
16+
v-bind:is="currentTabComponent"
17+
class="dynamic-component-demo-tab"
18+
></component>
19+
</keep-alive>
20+
</div>
21+
</template>
22+
23+
<script>
24+
import TabPosts from './tab-posts-dynamic'
25+
import TabArchive from './tab-archive'
26+
export default {
27+
components: {
28+
TabPosts,
29+
TabArchive
30+
},
31+
data() {
32+
return {
33+
currentTab: 'Posts',
34+
tabs: ['Posts', 'Archive']
35+
}
36+
},
37+
computed: {
38+
currentTabComponent() {
39+
return 'tab-' + this.currentTab.toLowerCase()
40+
}
41+
}
42+
}
43+
</script>
44+
45+
<style>
46+
.dynamic-component-demo-tab-button {
47+
padding: 6px 10px;
48+
border-top-left-radius: 3px;
49+
border-top-right-radius: 3px;
50+
border: 1px solid #ccc;
51+
cursor: pointer;
52+
background: #f0f0f0;
53+
margin-bottom: -1px;
54+
margin-right: -1px;
55+
}
56+
.dynamic-component-demo-tab-button:hover {
57+
background: #e0e0e0;
58+
}
59+
.dynamic-component-demo-tab-button.dynamic-component-demo-active {
60+
background: #e0e0e0;
61+
}
62+
.dynamic-component-demo-tab {
63+
border: 1px solid #ccc;
64+
padding: 10px;
65+
}
66+
.dynamic-component-demo-posts-tab {
67+
display: flex;
68+
}
69+
.dynamic-component-demo-posts-sidebar {
70+
max-width: 40vw;
71+
margin: 0 !important;
72+
padding: 0 10px 0 0 !important;
73+
list-style-type: none;
74+
border-right: 1px solid #ccc;
75+
}
76+
.dynamic-component-demo-posts-sidebar li {
77+
white-space: nowrap;
78+
text-overflow: ellipsis;
79+
overflow: hidden;
80+
cursor: pointer;
81+
}
82+
.dynamic-component-demo-posts-sidebar li:hover {
83+
background: #eee;
84+
}
85+
.dynamic-component-demo-posts-sidebar li.dynamic-component-demo-active {
86+
background: lightblue;
87+
}
88+
.dynamic-component-demo-post-container {
89+
padding-left: 10px;
90+
}
91+
.dynamic-component-demo-post > :first-child {
92+
margin-top: 0 !important;
93+
padding-top: 0 !important;
94+
}
95+
</style>
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<template>
2+
<div class="dynamic-component-demo-posts-tab">
3+
<ul class="dynamic-component-demo-posts-sidebar">
4+
<li
5+
v-for="post in posts"
6+
v-bind:key="post.id"
7+
v-bind:class="{
8+
'dynamic-component-demo-active': post === selectedPost
9+
}"
10+
v-on:click="selectedPost = post"
11+
>
12+
{{ post.title }}
13+
</li>
14+
</ul>
15+
<div class="dynamic-component-demo-post-container">
16+
<div v-if="selectedPost" class="dynamic-component-demo-post">
17+
<h3>{{ selectedPost.title }}</h3>
18+
<div v-html="selectedPost.content"></div>
19+
</div>
20+
<strong v-else>
21+
Click on a blog title to the left to view it.
22+
</strong>
23+
</div>
24+
</div>
25+
</template>
26+
27+
<script>
28+
export default {
29+
data() {
30+
return {
31+
posts: [
32+
{
33+
id: 1,
34+
title: 'Cat Ipsum',
35+
content:
36+
'<p>Dont wait for the storm to pass, dance in the rain kick up litter decide to want nothing to do with my owner today demand to be let outside at once, and expect owner to wait for me as i think about it cat cat moo moo lick ears lick paws so make meme, make cute face but lick the other cats. Kitty poochy chase imaginary bugs, but stand in front of the computer screen. Sweet beast cat dog hate mouse eat string barf pillow no baths hate everything stare at guinea pigs. My left donut is missing, as is my right loved it, hated it, loved it, hated it scoot butt on the rug cat not kitten around</p>'
37+
},
38+
{
39+
id: 2,
40+
title: 'Hipster Ipsum',
41+
content:
42+
'<p>Bushwick blue bottle scenester helvetica ugh, meh four loko. Put a bird on it lumbersexual franzen shabby chic, street art knausgaard trust fund shaman scenester live-edge mixtape taxidermy viral yuccie succulents. Keytar poke bicycle rights, crucifix street art neutra air plant PBR&B hoodie plaid venmo. Tilde swag art party fanny pack vinyl letterpress venmo jean shorts offal mumblecore. Vice blog gentrify mlkshk tattooed occupy snackwave, hoodie craft beer next level migas 8-bit chartreuse. Trust fund food truck drinking vinegar gochujang.</p>'
43+
},
44+
{
45+
id: 3,
46+
title: 'Cupcake Ipsum',
47+
content:
48+
'<p>Icing dessert soufflé lollipop chocolate bar sweet tart cake chupa chups. Soufflé marzipan jelly beans croissant toffee marzipan cupcake icing fruitcake. Muffin cake pudding soufflé wafer jelly bear claw sesame snaps marshmallow. Marzipan soufflé croissant lemon drops gingerbread sugar plum lemon drops apple pie gummies. Sweet roll donut oat cake toffee cake. Liquorice candy macaroon toffee cookie marzipan.</p>'
49+
}
50+
],
51+
selectedPost: null
52+
}
53+
}
54+
}
55+
</script>
56+
57+
<style lang="scss" scoped></style>

src/.vuepress/config.js

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ const sidebar = {
1414
'/guide/list',
1515
'/guide/events',
1616
'/guide/forms',
17-
'/guide/component-basics'
18-
]
17+
'/guide/component-basics',
18+
],
1919
},
2020
{
2121
title: 'Components In-Depth',
@@ -25,20 +25,21 @@ const sidebar = {
2525
'/guide/component-props',
2626
'/guide/component-custom-events',
2727
'/guide/component-slots',
28-
'/guide/component-provide-inject'
29-
]
28+
'/guide/component-provide-inject',
29+
'/guide/component-dynamic-async',
30+
],
3031
},
3132
{
3233
title: 'Migration to Vue 3',
3334
collapsable: true,
34-
children: ['migration']
35+
children: ['migration'],
3536
},
3637
{
3738
title: 'Contribute to the Docs',
3839
collapsable: true,
39-
children: ['writing-guide']
40-
}
41-
]
40+
children: ['writing-guide'],
41+
},
42+
],
4243
}
4344

4445
module.exports = {
@@ -50,9 +51,9 @@ module.exports = {
5051
{
5152
href:
5253
'https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css',
53-
rel: 'stylesheet'
54-
}
55-
]
54+
rel: 'stylesheet',
55+
},
56+
],
5657
],
5758
themeConfig: {
5859
nav: [
@@ -62,52 +63,52 @@ module.exports = {
6263
items: [
6364
{ text: 'Guide', link: '/guide/introduction' },
6465
{ text: 'Style Guide', link: '/style-guide/' },
65-
{ text: 'Tooling', link: '/tooling/' }
66-
]
66+
{ text: 'Tooling', link: '/tooling/' },
67+
],
6768
},
6869
{ text: 'API Reference', link: '/api/' },
6970
{
7071
text: 'Examples',
7172
ariaLabel: 'Examples Menu',
7273
items: [
7374
{ text: 'Examples', link: '/examples/' },
74-
{ text: 'Cookbook', link: '/cookbook/' }
75-
]
75+
{ text: 'Cookbook', link: '/cookbook/' },
76+
],
7677
},
7778
{
7879
text: 'Community',
7980
ariaLabel: 'Community Menu',
8081
items: [
8182
{ text: 'Team', link: '/community/team/' },
8283
{ text: 'Partners', link: '/community/partners/' },
83-
{ text: 'Themes', link: '/community/themes/' }
84-
]
85-
}
84+
{ text: 'Themes', link: '/community/themes/' },
85+
],
86+
},
8687
],
8788
sidebarDepth: 2,
8889
sidebar: {
8990
'/guide/': sidebar.guide,
90-
'/community/': sidebar.guide
91+
'/community/': sidebar.guide,
9192
},
92-
smoothScroll: false
93+
smoothScroll: false,
9394
},
9495
plugins: {
9596
'@vuepress/pwa': {
9697
serviceWorker: true,
9798
updatePopup: {
9899
'/': {
99100
message: 'New content is available.',
100-
buttonText: 'Refresh'
101-
}
102-
}
103-
}
101+
buttonText: 'Refresh',
102+
},
103+
},
104+
},
104105
},
105106
markdown: {
106107
/** @param {import('markdown-it')} md */
107-
extendMarkdown: md => {
108+
extendMarkdown: (md) => {
108109
md.options.highlight = require('./markdown/highlight')(
109110
md.options.highlight
110111
)
111-
}
112-
}
112+
},
113+
},
113114
}

0 commit comments

Comments
 (0)