-
Notifications
You must be signed in to change notification settings - Fork 21
/
index.html
326 lines (290 loc) · 9.56 KB
/
index.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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
pre {
border: 1px dashed #666;
padding: 10px;
white-space: pre-wrap;
}
arrow {
font-size: 30px;
color: red;
}
red {
color: red;
}
[\$for] {
color: blue;
}
body {
display: grid;
gap: 20px;
grid-template-rows: 60px 1fr;
grid-template-columns: 50% 50%;
}
h1 {
grid-column: span 2;
}
.ball{
width: 50px;
height: 50px;
background-color:cornflowerblue;
transition: .3s;
}
.ball.active{
transform: translateX(200px);
}
@keyframes slide {
to {
background-color: darksalmon;
}
}
</style>
<script>
function fn() {
alert(1)
}
</script>
</head>
<body>
<h1>web-template.js</h1>
<div class="left">
<pre><template id="template" rule="v-">
<h2 class="${title}"><red>${title}</red></h2>
<h3 <red>v-if="showh3"</red>>h3:${title}</h3>
<h4 v-if="showh4">h4:${title}</h4>
<ul class="list">
<li class="item" v-for="list" <red>key="${item.id}"</red>>
<input type="checkbox" >
<strong>[key = ${item.id}]</strong>
${ item.message }<span>${parseInt(item.num)}</span>
<div><i v-for="el in item.tag">${index+1}.${el} </i></div>
<input>
<button disabled="${item.disabled}">查看</button>
</li>
</ul>
<ul class="demo">
<li <red>v-for="(value,name,index) of object"</red>>
${ index } - ${ name } : ${ value }
</li>
</ul>
<div v-for="[1,2,3,4,5].reverse()">${item}</div>
乘法表
<div v-for="i in [1,2,3,4,5,6,7,8,9]">
<span v-for="j in [1,2,3,4,5,6,7,8,9]" v-if="i>=j"> ${i*j} </span>
</div>
</template>
</pre>
<arrow>+</arrow>
<pre>const data = {
title: 'Title',
showh3: true,
showh4: false,
object: {
title: 'How to do lists in Vue',
author: 'Jane Doe',
publishedAt: '2016-04-10'
},
list: [
{
id: "1",
message: '特朗普拒与拜登分享总统每日简报荐',
num: '482万',
tag: ['A', 'B', 'C'],
disabled: true
},
{
id: "2",
message: '最高法指令再审"百香果女孩"案新',
num: '465万',
tag: ['A', 'B'],
disabled: true
},
{
id: "3",
message: '拜登称特朗普拒认败选很尴尬沸',
num: '449万',
tag: ['A', 'B'],
disabled: true
}
]
}
}
</pre>
<pre><red>template.mount(res.data)</red></pre>
</div>
<div class="right">
<button id="toggle">切换数据源</button>
<input type="checkbox" id="diff"><label for="diff">是否开启 dom-diff</label>
<div is="template"></div>
</div>
<template id="template" rule="v-">
<h2 class="${title}" data-title="${title}">${title}</h2>
<h3 v-if="showh3">h3:${title}</h3>
<h3 v-show="showh3">h3:${title}</h3>
<div class="ball" :class="{active:showh3,m:showh4}"></div>
<h4 v-if="showh4">h4:${title}</h4>
<h4 hidden="${showh4}">hidden:h4:${title}</h4>
<ul class="list">
<li class="item" v-for="(item,index) in list" :key="item.id">
<input type="checkbox" v-model="list[index].disabled">
<strong>[key = ${item.id}]</strong>
${ item.message }<span>${parseInt(item.num)}</span>
<div><i v-for="(el, m) in list[index].tag">${m+list[index].tag[m]}</i></div>
<input>
<button disabled="${item.disabled}">查看</button>
</li>
</ul>
<ul class="demo">
<li v-for="(value,name,index) of object">
${ index } - ${ name } : ${ value }
</li>
</ul>
<div v-for="[1,2,3,4,5].reverse()">{{item}}</div>
乘法表
<div v-for="i in [1,2,3,4,5,6,7,8,9]">
<span v-for="j in [1,2,3,4,5,6,7,8,9]" v-if="i>=j"> ${i*j} </span>
</div>
</template>
<script src="./web-template.js"></script>
<script src="./web-diff.js"></script>
<script>
var res = {
code: 0,
data: {
title: 'Title',
showh3: true,
showh4: false,
object: {
title: 'How to do lists in Vue',
author: 'Jane Doe',
publishedAt: '2016-04-10'
},
list: [
{
id: "1",
message: '特朗普拒与拜登分享总统每日简报荐',
num: '482万',
tag: ['A', 'B', 'C'],
disabled: true
},
{
id: "2",
message: '最高法指令再审百香果女孩案新',
num: '465万',
tag: ['A', 'B'],
disabled: true
},
{
id: "3",
message: '拜登称特朗普拒认败选很尴尬沸',
num: '449万',
tag: ['A', 'B'],
disabled: true
}
]
}
}
var res2 = {
code: 0,
data: {
title: '22Title',
showh3: false,
showh4: false,
object: {
title: 'How to do lists in Vue',
author: 'Jane Doe',
publishedAt: '2016-04-10'
},
list: [
{
id: "2",
message: '天津一无症状感染者转为确诊病例',
num: '433万',
tag: ['A', 'C'],
disabled: false
},
{
id: "4",
message: '度小店 11.11好物新知节热',
num: '403万',
tag: ['A'],
disabled: false
},
{
id: "1",
message: 'new 度小店 11.11好物新知节热',
num: '14403万',
tag: ['A', 'B'],
disabled: false
},
{
id: "5",
message: 'new 度小店 11.11好物新知节热',
num: '14403万',
tag: ['A'],
disabled: true
},
]
}
}
console.time('init')
template.mount(res.data)
// template.model({
// data: {
// title: '默认标题',
// showh3: false,
// showh4: false,
// object: {},
// checked: false,
// list: [{
// id: "1",
// message: '特朗普拒与拜登分享总统每日简报荐',
// num: '482万',
// tag: ['A', 'B', 'C'],
// disabled: true
// },
// {
// id: "2",
// message: '最高法指令再审"百香果女孩"案新',
// num: '465万',
// tag: ['A', 'B'],
// disabled: true
// }
// ]
// },
// methods: {
// showId(item){
// console.log(item)
// console.log(this)
// console.log(event)
// // this.title = ev.target.textContent
// },
// change(e){
// console.log(event)
// this.checked = !this.checked
// }
// },
// init(){
// console.log('初始化完成')
// console.log(this)
// }
// })
console.timeEnd('init')
toggle.onclick = function(){
console.time('render')
if(this.flag){
template.mount(res.data, diff.checked)
}else{
template.mount(res2.data, diff.checked)
}
console.timeEnd('render')
this.flag = !this.flag;
}
</script>
</body>
</html>