<!-- HTML -->
<div id="keyDiv-demo">
<div>
<template v-if="loginType==='username'">
<label>Username</label>
<input placeholder="Enter your username">
</template>
<template v-else>
<label>Email</label>
<input placeholder="Enter your email address">
</template>
</div>
<button v-on:click="changename">Toggle login type</button>
</div>
// 对应的vue
var vueifKey = new Vue({
el:"#keyDiv-demo",
data:{
loginType:'username'
},
methods:{
changename:function(){
var n = 0;
n += 1;
var vm = this;
if(n%2===0){
vm.loginType='email'
}else{
vm.loginType='username'
}
}
}
})
我想点击button之后 loginType就能改变了,但是写完发现改变不了 又不知道错在哪 那位前辈帮忙看看?
当年话下
相关分类