Vue controls the hiding and display of elements: 1. Use the "v-if" and "v-else" instructions to control the visibility; 2. Use the "v-show" instruction to switch the CSS of the element. The display attribute controls visibility; 3. Directly set the display or opacity style to the element to control visibility.
The operating environment of this tutorial: windows7 system, vue2.9.6 version, DELL G3 computer.
Several methods to control the hiding and display of elements in vue
1. v-if v-else instruction
2. v-show
<div v-show="showGroup"> <div class="formTitle">图层组</div > </div >
For example, if you want to hide the above div, then add a v-show attribute to this div. You can name it whatever you want
and then set the default value of showGroup to false in the js code. That is, when it is first started, it will not be displayed by default. If you want to display this div later, you can directly set the vm. showGroup=true
3. display:none & opacity: 0 [Get the dom element through attribute binding or ref and set display:none or set transparency ] && Move the element outside the visible area of the document (transform:translate()) [Hide and display in disguise, combined with animation to achieve cool effects]
[Related recommendations: "vue.js tutorial 》】
The above is the detailed content of How to control the hiding and display of elements in vue. For more information, please follow other related articles on the PHP Chinese website!