-
Notifications
You must be signed in to change notification settings - Fork 476
/
Copy path5-4 transition-mode .html
103 lines (94 loc) · 2.76 KB
/
5-4 transition-mode .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
<!DOCTYPE html>
<html lang="en">
<head>
<script type="text/javascript" src="vue.js"></script>
<meta charset="UTF-8">
<title>5-4</title>
<style>
.fade-transition {
transition: opacity .3s ease;
}
.fade-enter, .fade-leave {
opacity: 0;
}
</style>
</head>
<body>
<br>
<h3>组件动态切换的过渡 </h3>
<component
:is="currentView"
keep-alive
transition="fade"
transition-mode="out-in">
</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: '<div>component is home <c1 str1="home"></c1></div>',
// activate it works
activate: function(done) {
console.log('home activate called');
setTimeout(function() {
console.log('home activate done');
done();
}, 100);
},
},
posts: {
template: '<div>component is posts <c1 str1="posts"></c1></div>',
// activate it works
activate: function(done) {
console.log('posts activate called');
setTimeout(function() {
console.log('posts activate done');
done();
}, 100);
},
},
archive: {
template: '<div>component is archive <c1 str1="archive"></c1></div>',
// activate it works
activate: function(done) {
console.log('archive activate called');
setTimeout(function() {
console.log('archive activate done');
done();
}, 100);
},
}
},
events: {
'parent-events1': function(str1) {
this.currentView = str1;
}
}
})
</script>
</body>
</html>