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
| <div id="app">
<keep-alive>
<component :is="whichCom"></component>
</keep-alive>
<button @click="whichCom = 'user-name'">username</button>
<button @click="whichCom = 'pass-word'">password</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>
|