Home >Web Front-end >Front-end Q&A >How to control the hiding and display of elements in vue

How to control the hiding and display of elements in vue

青灯夜游
青灯夜游Original
2022-01-04 12:15:1219118browse

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.

How to control the hiding and display of elements in vue

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

How to control the hiding and display of elements in vue

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn