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
| <style type="text/css">
.com-leave, .com-enter-to{
transform: translateX(0);
}
.com-leave-to,.com-enter{
transform: translateX(-150%);
}
.com-leave-active,.com-enter-active{
transition: transform 0.8s ease;
}
</style>
</head>
<body>
<div id="app">
<transition mode="out-in" name="com">
<keep-alive>
<component :is="whichCom"></component>
</keep-alive>
</transition>
<button @click="whichCom = (whichCom == 'user-name') ? 'pass-word' : 'user-name';">username</button>
</div>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script src="https://unpkg.com/vue-router/dist/vue-router.js"></script>
<script type="text/javascript">
const userName = {
template : `<div>username : <input type="text" /></div>`
}
const passWord = {
template : `<div>password : <input type="password" /></div>`
}
var app = new Vue({
el : "#app",
components : {
userName,
passWord
},
data : {
whichCom : "user-name"
}
})
</script>
</body>
|