Home > Web Front-end > Vue.js > body text

How to hide elements in vue

青灯夜游
Release: 2021-10-27 14:57:39
Original
15813 people have browsed it

Vue method of hiding elements: 1. Use the "v-if" command to display or hide elements by dynamically adding or deleting DOM elements to the DOM tree; 2. Use "v-show" Instructions to control visibility by setting the display style attribute of DOM elements.

How to hide elements in vue

The operating environment of this tutorial: windows7 system, vue2.9.6 version, DELL G3 computer.

vue controls the display and hiding of elements

Solution:

v Both the -if instruction and the v-show instruction can dynamically control the display and hiding of DOM elements based on the value. v-if and v-show are commonly used internal instructions in Vue. The responsibility of the instruction is to change certain special elements when the value of the expression changes. Behaviors are applied to the DOM.

  • v-if will directly delete the element

  • ##v -show just hides, simply toggling the element's CSS property display.

   <p v-show="showGroup">
        <p class="formTitle">图层组</p >
    </p >
Copy after login
For example, if you want to hide the p above, then add a v-show attribute to this p. 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 p later, you can set the vm directly. showGroup=true

Related recommendations: "

vue.js tutorial"

The above is the detailed content of How to hide elements in vue. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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