<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>输入框切换显示与隐藏效果</title>
</head>
<style>
#app {
width: 600px;
margin: auto;
}
li {
list-style: none;
}
p {
display: inline-block;
margin: 0 3px;
text-align: center;
float: left;
}
</style>
<body>
<div id="app">
<button @click="show = !show">{{show?"显示":"隐藏"}}</button>
<!-- 不加key达不到input框切换的效果 -->
<input type="text" v-if="show==true" :key="2">
<input type="text" v-else :key="3">
</div>
</body>
<script src="./vue.js"></script>
<script>
const vm = new Vue({
el: "#app",
data: {
show:true,
}
})
</script>
</html>