Vue-条件渲染
条件渲染
条件渲染的属性有两个:
1.v-if/v-else
v-if的方法是删除元素
<body>
<div id="app">
<div v-if="flag">上课</div>
<div v-if="n">下课</div>
<button @click="fn">切换</button>
</div>
</body>
<script>
new Vue({
el:"#app",
data:{
flag:true,
n:false
},
methods:{
fn(){
this.flag=!this.flag
this.n=!this.n
}
}
})
</script>
2.v-show
v-show的方法是隐藏元素,也就是将元素的display设置为none
<body>
<div id="app">
<div v-show="flag">上课</div>
<div v-show="n">下课</div>
<button @click="fn">切换</button>
</div>
</body>
<script>
new Vue({
el:"#app",
data:{
flag:true,
n:false
},
methods:{
fn(){
this.flag=!this.flag
this.n=!this.n
}
}
})
</script>
本文来自博客园,作者:前端小白银,转载请注明原文链接:https://www.cnblogs.com/forever-ljf/p/16641491.html

浙公网安备 33010602011771号