Prefacev-show and v-if are commonly used Vue instructions, often used to determine the rendering of some code blocks, but what is the specific difference between the two? ? ? First, let's take a look at the introduction of the Vue Chinese community documentation: The Vue Chinese community documentation simply states: Conditional judgment is performed during initial rendering; 1. v-showThe function of the v-show instruction is to switch the display state of the element according to the true or false value. It is responsive Syntax expression v-show = "expression" The principle is to modify the CSS property (display) of the element to decide whether to display or hide it. The content after the instruction will eventually be parsed as a Boolean value When the value is true, the element is displayed; when the value is false, the element is hidden. After the data changes, the display status of the corresponding elements will also be updated synchronously <body> <div id="app"> <input type="button" value="Toggle display" @click="changeIsShow" /> <p v-show="isShow">I'm not pretending anymore. I'm telling you the truth. Yes, I'm the one you're looking for</p> </div> <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script> <script> var app = new Vue({ el:"#app", data:{ isShow:false }, methods:{ changeIsShow(){ this.isShow = !this.isShow } } }) </script> </body> 2. v-ifThe function of the v-if instruction: switch the display state of the element according to the truth or falseness of the expression v-if = "expression" The essence is to switch the display by manipulating DOM elements When the value of the expression is true, the element exists in the DOM tree, and when it is false, it is removed from the DOM tree. <body> <div id="app"> <input type="button" value="Click me to switch display" @click="changeIsShow" /> <p v-if="isShow">I'm not pretending anymore. I'm telling you the truth. Yes, I'm the one you're looking for</p> </div> <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script> <script> var app = new Vue({ el:"#app", data:{ isShow:false }, methods:{ changeIsShow(){ this.isShow = !this.isShow } } }) </script> </body> 3. The difference between v-show and v-if1. Differences in principle
2. Differences in usage scenarios
SummarizeThis is the end of this article about the difference between the commonly used Vue instructions v-if and v-show. For more information about the difference between the Vue instructions v-if and v-show, please search for previous articles on 123WORDPRESS.COM or continue to browse the related articles below. I hope you will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: MySQL 8.0.22 winx64 installation and configuration graphic tutorial
Table of contents 1. Introduction 2. Initial Vue ...
Table of contents Oracle Isolation Levels MySQL I...
MySQL is now the database used by most companies ...
As a front-end monkey, whether it is during an in...
The search binary tree implementation in JavaScri...
This article records the installation tutorial of...
Two days ago, I took advantage of the Double 11 s...
This article shares the specific code of Node.js+...
When Mysql associates two tables, an error messag...
HTML img tag: defines an image to be introduced in...
The content property was introduced as early as C...
How can we say that we should avoid 404? The reas...
First, attach the code below the effect diagram &...
Table of contents Using routing plugins in a modu...
Preface: In project development, some business ta...