vue默认会复用已有元素,用key可以区分是否复用
label聚焦,点击label可以将焦点聚焦到for所对应的id
<div class="app">
<span v-if="show">
<label for="number">用户账号</label>
<input id="number" placeholder="用户账号" key="number">
</span>
<span v-else>
<label for="email">用户邮箱</label>
<input id="email" placeholder="用户邮箱" key="email">
</span>
<button v-on:click="show=!show">切换账号</button>
</div>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script>
var vm=new Vue({
el:".app",
data:{
show:true
}
})
</script>