<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div id="app">
<span v-if="isUser">
<label for="Username">账号</label>
<input type="text" id="Username" placeholder="zhh">
</span>
<span v-else>
<label for="Username">邮箱</label>
<input type="text" id="email" placeholder="you">
</span>
<button @click="isUser = !isUser" >切换类型</button>
</div>
<script src="./vue.js"></script>
<script>
const app = new Vue({
el: '#app',
data : {
isUser: true
}
})
</script>
</body>
</html>
小问题:
key 可以解决切换时内容框未清零的现象:
使两个input 的key值不同
<input type="text" id="Username" placeholder="zhh" key="Username">