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. Mini Program Subcontracting ...
Table of contents What is FormData? A practical e...
This article example shares the specific code of ...
Table of contents Preface Scenario Analysis Summa...
For front-end developers, ensuring that the code ...
/****************** * Kernel debugging technology...
Version update, the password field in the origina...
This article example shares the specific code of ...
Windows 10 now supports Linux subsystem, saying g...
Preface Named slots are bound to elements using t...
Table of contents Preface start Basic layout Data...
Table of contents Before transformation: After tr...
CSS3 can create animations, which can replace man...
A colleague once told me to use a temporary table...
Copy code The code is as follows: <!DOCTYPE ht...