-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest2.0.html
768 lines (739 loc) · 16.6 KB
/
test2.0.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
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="description" content=""/>
<meta name="keywords" content="html"/>
<meta name="author" content="Shyla Nie"/>
<meta name="viewport" content="initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no">
<meta name="format-detection" content="telphone=no, email=no"/>
<meta name="full-screen" content="yes">
<meta name="x5-fullscreen" content="true">
<title>Vue 2.0</title>
<!-- <link rel="stylesheet" href="D:/github/vue/animate.css" /> -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.5.2/animate.min.css">
<style type="text/css">
*{
padding:0;
margin:0;
}
body{
margin:0 auto;
font-size:24px;
font-weight:700;
background-color:#f5f5dc;
}
.mask-layer{
position:fixed;
width:100%;
height:100%;
background-color:black;
}
#awesome-dots{
position:relative;
margin: 0 auto;
top: 300px;
width: 100px;
height: 30px;
background: radial-gradient(circle at 15px 10px , #FFFFFF 3px, rgba(0, 0, 0, 0) 4px), radial-gradient(circle at 40px 10px , #FFFFFF 3px, rgba(0, 0, 0, 0) 4px), radial-gradient(circle at 65px 10px , #FFFFFF 3px, rgba(0, 0, 0, 0) 4px), radial-gradient(circle at 90px 10px , #FFFFFF 3px, rgba(0, 0, 0, 0) 4px);
animation: load 3s 400ms linear infinite;
}
@keyframes load{
0% {
opacity: 0;
transform: translateX(-300px);
}
33% {
opacity: 0.8;
transform: translateX(-100px);
}
50%{
opacity: 1;
transform: translateX(0px);
}
66% {
opacity: 0.8;
tranform: translateX(100px);
}
100% {
opacity: 0;
transform: translateX(300px);
}
}
.contain{
width:90%;
margin:0 auto;
padding:10px 0;
}
.contain>div{
margin-bottom:20px;
}
.contain>div>h3{
color:brown;
padding-left:3px;
margin-bottom:5px;
border-left:6px solid #983b12;
border-radius:4px 0 0 4px;
}
.contain>div>div{
margin-bottom:5px;
}
.contain button{
font-size:14px;
padding:3px 8px;
background:#fff;
border-radius:4px;
border:1px solid #ccc;
}
.contain input{
font-size:14px;
padding:3px 5px;
border-radius:4px;
border:1px solid #c6deb3;
}
.red{
color:red;
}
</style>
</head>
<body>
<div id="maskLayer" class="mask-layer">
<div id="awesome-dots"></div>
</div>
<div class="contain">
<!-- component start -->
<div id="example0">
<h3>example 0 eq:全局注册</h3>
<example-0></example-0>
</div>
<div id="example1">
<h3>example 1 eq:局部注册</h3>
<example-1></example-1>
</div>
<div id="example2">
<h3>example 2 eq:data函数</h3>
<div>
<example-2a></example-2a>
<example-2a></example-2a>
</div>
<div>
<example-2b></example-2b>
<example-2b></example-2b>
</div>
</div>
<div id="example3">
<h3>example 3 eq:prop</h3>
<div>
<input v-model.number="say">
<example-3 :message="say"></example-3>
<span>{{num_type}}</span>
</div>
</div>
<div id="example4">
<h3>example 4 eq:监听子级</h3>
<div>{{total}}</div>
<example-4 v-on:increment="increTotal"></example-4>
<example-4 v-on:increment="increTotal"></example-4>
</div>
<div id="example5">
<h3>example 5</h3>
<div>{{fullName}}</div>
<example-5 v-on:submit="getFullName"></example-5>
<example-5 v-on:submit="getFullName"></example-5>
</div>
<div id="example6">
<h3>example 6 eq:监听子级(表单)</h3>
<div>{{message}}</div>
<example-6 label="islabel" v-model="message"></example-6>
</div>
<div id="example7">
<h3>example 7 eg:单个slot</h3>
<div>I am father</div>
<example-7>
<div>有我就不显示slot啦</div>
</example-7>
</div>
<div id="example8">
<h3>example 8 eg:具名slot</h3>
<div>I am father</div>
<example-8>
<p slot="header">我才是header</p>
</example-8>
</div>
<div id="example9">
<h3>example 9 eg:动态组件</h3>
<button v-on:click="changeComp(0)">change</button>
<button v-on:click="changeComp(1)">change</button>
<button v-on:click="changeComp(2)">change</button>
<div>
<keep-alive>
<example-9 v-bind:is="currentComp"></example-9>
</keep-alive>
</div>
</div>
<div id="example10">
<h3>example 10 eg:索引ref</h3>
<example-10></example-10>
<example-10 ref="ex10Ref"></example-10>
</div>
<div id="example11">
<h3>example 11 eg:x-template</h3>
<example-11></example-11>
</div>
<!-- component end -->
<!-- others -->
<div id="example12">
<h3>example 12 eq:计算属性</h3>
<div>{{message}}</div>
<div>{{c_message()}}</div>
</div>
<div id="example13">
<h3>example 13 eq:对象迭代</h3>
<div v-for="(value,key) in list">{{key}}:{{value}}</div>
</div>
<div id="example14">
<h3>example 14</h3>
<p><span v-for="item in number">{{item}}-</span></p>
<span v-for="item in list">{{item}}-</span>
<p><span v-for="item in filterNum(number)">{{item}}-</span></p>
</div>
<div id="example15">
<h3>example 15</h3>
<p>
<span>h{{level}}</span>
<button v-on:click="levelCount">click</button>
</p>
<example-15 v-bind:level="level">Hello World</example-15>
</div>
<div id="example16">
<h3>example 16 eq:自定义指令</h3>
<input :value="name" v-focus:ag="message">
</div>
<!-- others -->
<!-- transition start -->
<div id="exampleA">
<h3>example a</h3>
<button v-on:click="fade = !fade">toggle</button>
<button v-on:click="bounce = !bounce">toggle</button>
<transition name="exa-fade">
<p v-if="fade">click button you can hidden me</p>
</transition>
<transition name="exa-bounce">
<p v-if="bounce">click button2 you can hidden me</p>
</transition>
</div>
<style>
.exa-fade-enter-active,.exa-fade-leave-active{
transition:opacity 0.5s;
}
.exa-fade-enter,.exa-fade-leave-active{
opacity:0;
}
.exa-bounce-enter-active{
animation:bounce-in 0.5s;
}
.exa-bounce-leave-active{
animation:bounce-out 0.5s;
}
@keyframes bounce-in{
0%{
transform:scale(0);
}
50%{
transform:scale(1.5);
}
100%{
transform:scale(1);
}
}
@keyframes bounce-out{
0%{
transform:scale(1);
}
50%{
transform:scale(1.5);
}
100%{
transform:scale(0);
}
}
</style>
<div id="exampleB">
<h3>example b</h3>
<button v-on:click="show = !show">toggle</button>
<transition
name="custom-classes-transition"
enter-active-class="animated tada"
leave-active-class="animated bounceOutRight"
v-on:before-enter="beforeEnter"
v-on:after-leave="afterLeave">
<p v-if="show">use animate css</p>
</transition>
<transition
appear
appear-class="animated zoomOutUp"
appear-active-class="animated zoomOutUp">
<p v-if="show">use the same animate css</p>
</transition>
</div>
<div id="exampleC">
<h3>example c</h3>
<transition>
<button v-bind:key="docState">
{{buttonMess}}
</button>
</transition>
</div>
<div id="exampleD">
<h3>example d</h3>
<input v-model="query">
<transition-group tag="ol"
name="exd-stagger"
enter-active-class="animated fadeInDown"
leave-active-class="animated fadeOutUp">
<li style="height:30px;margin-left:40px"
v-for="(item,index) in messList"
v-bind:key="item.mess"
v-bind:data-index="index">
{{item.mess}}
</li>
</transition-group>
</div>
<!-- transition end -->
</div>
<script src="https://npmcdn.com/[email protected]/dist/vue.js"></script>
<!-- <script src="D:/sj/vueJS/vue2.0.5.js"></script> -->
<script>
window.onload = function(){
var maskLayer = document.getElementById("maskLayer");
maskLayer.style.display = "none";
//example d
new Vue({
el:"#exampleD",
data:{
query:'',
list:[
{mess:"yuiokm"},
{mess:"njdkfj"},
{mess:"kgnerng"},
{mess:"sgkfjng"},
{mess:"eroigv"}
]
},
computed:{
messList:function(){
var vm = this
return this.list.filter(function(item){
return item.mess.toLowerCase().indexOf(vm.query.toLowerCase()) !== -1
})
}
}
})
//example c
new Vue({
el:"#exampleC",
data:{
docState:"saved"
},
computed:{
buttonMess:function(){
switch(this.docState){
case 'saved' : return 'Edit'
case 'edited' : return 'Save'
case 'editing' : return 'Cancel'
}
}
}
})
//example b
new Vue({
el:"#exampleB",
data:{
show:true
},
methods:{
beforeEnter:function(){
// console.log("before-enter")
},
afterLeave:function(){
// console.log("after-leave")
}
}
})
//example a
new Vue({
el:"#exampleA",
data:{
fade:true,
bounce:true
}
})
//example
Vue.mixin({
created:function(){
var my_option = this.$options.my_option
if(my_option){
// console.log(my_option)
}
}
})
new Vue({
my_option:"这是全局mixins"
})
//example
var mixin0 = {
created:function(){
this.hello()
},
methods:{
hello:function(){
// console.log("hello my mixin")
}
}
}
var components0 = Vue.extend({
mixins:[mixin0]
})
var showComponents0 = new components0()
//example 16
Vue.directive("focus",{
inserted:function(el,binding,vnode){
// console.log("focus your input")
// el.focus()
var mess = "name:"+binding.name+" value:"+binding.value+" expression:"+binding.expression+" argument:"+binding.arg+" modifiers:"+JSON.stringify(binding.modifiers)
// console.log(mess)
}
})//全局指令
new Vue({
el:"#example16",
data:{
name:"yes"
},
methods:{
message:function(){
console.log(this.name)
}
}
})
//example 15
var ex15GetContent = function(children){
return children.map(function(node){
return node.children ? ex15GetContent(node.children) : node.text
}).join('')
}
Vue.component("example-15",{
render:function(createElement){
var headingID = ex15GetContent(this.$slots.default)
.toLowerCase()
.replace(/\W+/g,'-')
.replace(/(^\-|\-$)/g,'')
return createElement('h'+this.level,[
createElement('a',{
attrs:{
name:headingID,
href:"#"+headingID
}
},this.$slots.default)
])
/*相当于:
<a name="headingID" href="#headingID">
this.$slots.default
</a>*/
},
props:{
level:{
type:Number,
required:true
}
}
})
new Vue({
el:"#example15",
data:{
level:1
},
methods:{
levelCount:function(){
this.level += 1
if(this.level >= 7){
this.level = 1
}
}
}
})
//example 14
new Vue({
el:"#example14",
data:{
number:[1,44,6,9,43,98]
},
computed:{
list:function(){
return this.number.filter(function(number){
return number%2 === 0
})
}
},
methods:{
filterNum:function(){
return this.number.filter(function(number){
return number%2 === 0
})
}
}
})
//example 13
new Vue({
el:"#example13",
data:{
list:{
name:'she',
age:60,
collect:3
}
}
})
//example 12
new Vue({
el:"#example12",
data:{
message:"leave"
},
methods:{
c_message:function(){
return this.message.split('').reverse().join('')
}
}
})
//example 11
Vue.component("example-11",{
template:"#ex11Temp"
})
new Vue({
el:"#example11"
})
//example 10
var ex10Comp = {
template:"<button v-bind:style='styleType'>change color</button>",
data:function(){
return{
styleType:{
color:"red"
}
}
}
}
var ex10Vm = new Vue({
el:"#example10",
components:{
"example-10":ex10Comp
}
})
var ex10Child = ex10Vm.$refs.ex10Ref
ex10Child.styleType.color = "green"
//example 9
var ex9Btn_0 = {
template:"<button>first</button>"
}
var ex9Btn_1 = {
template:"<button>second</button>"
}
var ex9Btn_2 = {
template:"<button>third</button>"
}
new Vue({
el:"#example9",
data:{
currentComp:ex9Btn_0,
compList:[ex9Btn_0,ex9Btn_1,ex9Btn_2]
},
methods:{
changeComp:function(_index){
console.log(_index)
this.currentComp = this.compList[_index]
}
}
})
//example 8
var ex8Comp = {
template:"\
<div>\
<p>I am child</p>\
<div><slot class='red' name='header'>我是header</slot></div>\
<div><slot name='footer'>我是footer</slot></div>\
</div>\
"
}
new Vue({
el:"#example8",
components:{
"example-8":ex8Comp
}
})
//example 7
Vue.component("example-7",{
template:"\
<div>\
<p>I am child</p>\
<slot>显示我呀</slot>\
</div>\
"
})
new Vue({
el:"#example7"
})
//example 6
Vue.component("example-6",{
template:"\
<div>\
<label v-bind:for='randomID'>{{label}}:</label>\
<input v-bind:id='randomID' v-bind:value='value' v-on:input='onInput'>\
</div>\
",//value就是message的值
props:['value','label'],
data:function(){
return{
randomID:'input-'+Math.random()
}
},
methods:{
onInput:function(event){
this.$emit("input",event.target.value)
}
}
})
new Vue({
el:"#example6",
data:{
message:'hello'
}
})
//example 5
var ex5FullName
var ex5Input = "<input v-model='name'>"
var ex5Button = "<button v-on:click='submit'>submit</button>"
Vue.component("example-5",{
template:"<div>"+ex5Input+ex5Button+"</div>",
data:function(){
return{
name:''
}
},
methods:{
submit:function(){
ex5FullName = this.name
this.$emit("submit")
}
}
})
var ex5Vm = new Vue({
el:"#example5",
data:{
fullName:'hey'
},
methods:{
getFullName:function(){
this.fullName = ex5FullName
}
}
})
//example 4
Vue.component("example-4",{
template:"<button v-on:click='increment'>{{counter}}</button>",
data:function(){
return{
counter:0
}
},
methods:{
increment:function(){
this.counter += 1
this.$emit("increment")
}
}
})
new Vue({
el:"#example4",
data:{
total:0
},
methods:{
increTotal:function(){
this.total += 1
}
}
})
//example 3
Vue.component("example-3",{
props:{
"message":{
type:Number,
required:true,
default:0
}
},
template:"<span>{{message}}</span>"
})
new Vue({
el:"#example3",
data:{
say:33
},
computed:{
num_type:function(){
return typeof(this.say);
}
}
})
//example 2
var ex2Child = {
template:"<button v-on:click='counter_b +=1'>{{counter_b}}</button>",
data:function(){
return {
counter_b:0//每个组件返回新的data
}
}
}
var ex2Data = {
counter_a:0
}
Vue.component("example-2a",{
template:"<button v-on:click='counter_a +=1'>{{counter_a}}</button>",
data:function(){
return ex2Data//每个组件都是同一个data
}
})
new Vue({
el:"#example2",
components:{
"example-2b":ex2Child
}
})
//example 1
var ex1Child = {
template:"<div>just a component</div>"
}
new Vue({
el:"#example1",
components:{
'example-1':ex1Child
}
})
//example 0
Vue.component("example-0",{
template:"<div>I am just a component</div>"
})
new Vue({
el:"#example0"
})
}
</script>
<script type="text/x-template" id="ex11Temp">
<button>x-template</button>
</script>
<script type="text/x-template">
<div>
</div>
</script>
</body>
</html>