-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path05.html
204 lines (201 loc) · 4.51 KB
/
05.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>task-05</title>
<script src="vue/vue.js"></script>
</head>
<body>
<div id="app-01" >
<component-a></component-a>
</div>
<div id="app-02">
<component-b v-model='d_count'>{{d_count}}</component-b>
<span>{{d_count}}</span>
</div>
<parent-component id="app-03"></parent-component>
<parent-list id="app-04" v-bind:mylist="mylist"></parent-list>
<text1 id="app-05" v-bind:message="message"></text1>
<br>
<keep-alive><component id="app-06" v-bind:is="currentView"></component></keep-alive>
<div id="app-07">
<recursion-component :count="0"></recursion-component>
</div>
<div id="app-08">
<tree-folder :folder="folder"></tree-folder>
</div>
<div id="app-09">
<parent-com><span>啦啦啦</span></parent-com>
</div>
<div id="app-10">
<hello-world></hello-world>
</div>
<script type="text/x-template" id="hello-world-template">
<p>Hello hello hello</p>
</script>
<script>
var bus=new Vue()
var app01=new Vue({
el:'#app-01',
components:{
'component-a':{
template:'<button v-on:click="increment">{{count}}</button>',
data:function(){
return {count:0}
},
methods:{
increment:function(){
this.count+=1
bus.$emit('busEvent',this.count)
}
}
}
}
})
var app02=new Vue({
el:'#app-02',
data:{
d_count:0
},
components:{
'component-b':{
template:'<button>111-{{d_count}}</button>',
props:['d_count'],
mounted:function(){
bus.$on('busEvent',function(i){
return this.d_count=i
})
}
}
}
})
Vue.component('child',{
template:'<div><slot text="hello from child"></slot></div>'
})
var app03=new Vue({
el:'#app-03',
components:{
'parent-component':{
template:'<div>\
<child>\
<template scope="props">\
<span>hello from parent</span>\
<span>{{props.text}}</span>\
</template>\
</child></div>'
}
}
})
Vue.component('child-list',{
props:['mylist'],
template:'<ul><slot name="item" v-for="item in mylist" v-bind:text="item.text"></slot></ul>'
})
var app04=new Vue({
el:'#app-04',
data:{
mylist:[
{text:'蔬菜'},
{text:'水果'},
{text:'肉'}
]
},
components:{
'parent-list':{
props:['mylist'],
template:'<child-list v-bind:mylist="mylist">\
<template slot="item" scope="props">\
<li>{{props.text}}</li>\
</template>\
</child-list>'
}
}
})
Vue.component('text1',{
props:['message'],
template:'<span>{{message}}</span>'
})
var app05=new Vue({
el:'#app-05',
data:{
message:'hello11'
}
})
var home={
template:'<span>home</span>'
}
var app06=new Vue({
el:'#app-06',
data:{
currentView:'archive'
},
components:{
'posts':{
template:'<span>posts</span>'
},
archive:{
template:'<span>archive</span>'
}
}
})
Vue.component('async-example',function(resolve,reject){
setTimeout(function(){
resolve({
template:'<div>I am async!</div>'
})
},1000)
})
Vue.component('recursion-component',{
props:['count'],
name:'count',
template:'<div><span>{{count}}</span><recursion-component :count="count+1" v-if="count<10"></recursion-component></div>'
})
var app07=new Vue({
el:'#app-07',
})
Vue.component('tree-folder',{
template:'<p><span>{{folder.name}}</span><tree-folder-contents :children="folder.children"/></p>',
props:['folder']
})
Vue.component('tree-folder-contents',{
template:'<ul><li v-for="child in children">\
<tree-folder v-if="child.children" :folder="child"/>\
<span v-else>{{child.name}}</span>\
</li></ul>',
props:['children']
})
var app08=new Vue({
el:'#app-08',
data:{
folder:{
name:'总目录',
children:[
{name:"二层目录1"},
{name:"二层目录2",
children:[
{name:"三层目录1"},
{name:"三层目录1"}
]
},
{name:'二层目录3'}
]
}
}
})
Vue.component('child-com',{
template:'<div><span>this is from child</span><slot></slot></div>'
})
Vue.component('parent-com',{
template:'<div><child-com><span>this is part of parents</span></child-com></div>'
})
var app09=new Vue({
el:'#app-09'
})
Vue.component('hello-world', {
template: '#hello-world-template'
})
var app10=new Vue({
el:'#app-10'
})
</script>
</body>
</html>