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

青灯夜游
Release: 2022-01-04 12:15:12
Original
19129 people have browsed it

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 >
Copy after login

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!

Related labels:
vue
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template