-
Notifications
You must be signed in to change notification settings - Fork 476
/
Copy path5-2 Dynamic Components Keep alive.html
64 lines (59 loc) · 1.57 KB
/
5-2 Dynamic Components Keep alive.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<!DOCTYPE html>
<html lang="en">
<head>
<script type="text/javascript" src="vue.js"></script>
<meta charset="UTF-8">
<title>5-2</title>
</head>
<body>
<br>
<h3>组件的data 会被缓存</h3>
<component :is="currentView" keep-alive>
<!-- component changes when vm.currentview changes! -->
</component>
<script>
Vue.component('c1', {
template: `
<input v-model="a">{{a}}
<button @click="m('home')">home</button>
<button @click="m('posts')">posts</button>
<button @click="m('archive')">archive</button>
<button @click="m(str1)">{{str1}}</button>
`,
props: ['str1'],
methods: {
m: function(str1) {
this.$dispatch('parent-events1', str1)
}
},
data: function() {
return {
a: 1
}
}
});
new Vue({
el: 'body',
data: {
currentView: 'home'
},
components: {
home: {
template: 'component is home <c1 str1="home"></c1>'
},
posts: {
template: 'component is posts <c1 str1="posts"></c1>'
},
archive: {
template: 'component is archive <c1 str1="archive"></c1>'
}
},
events: {
'parent-events1': function(str1) {
this.currentView = str1;
}
}
})
</script>
</body>
</html>