Home >Web Front-end >Vue.js >How to hide or show elements in vue.js
Vue.js method of hiding or showing elements: Use the v-show directive to achieve this, for example [window.onload = function(){var vm = new Vue({el:'#box',data: {isShow:false,},metho...】.

The operating environment of this article: windows10 system, vue.js 2.9, thinkpad t480 computer.
In vue, if we want to control the hiding or display of elements, we can use the v-show directive.
The v-show directive is used to control the display or hiding of elements.
v-show="true/false" //控制元素显示/隐藏
Example:
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset="utf-8">
<script src="http://unpkg.com/vue/dist/vue.js"></script>
<script type="text/javascript">
window.onload = function(){
var vm = new Vue({
el:'#box',
data:{
isShow:false,
},
methods:{
toggle:function(){
this.isShow = !this.isShow;
}
}
});
}
</script>
</head>
<body>
<div id="box">
<input type="button" value="toggle" v-on:click="toggle()"> <br />
<div v-show="isShow" style="width: 100px;height: 100px;background: red"></div>
</div>
</body>
</html>Recommended learning:php training
The above is the detailed content of How to hide or show elements in vue.js. For more information, please follow other related articles on the PHP Chinese website!