Home>Article>Web Front-end> How to hide elements in vue

How to hide elements in vue

青灯夜游
青灯夜游 Original
2021-10-27 14:57:39 15682browse

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.

图层组

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!

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