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
1. Introduction MySQL is used in the project. I i...
step Place the prepared static resource files in ...
This article shares the specific code of Vue to i...
As the platform continues to grow, the project...
This article introduces common problems of Xshell...
Table of contents 1. Installation 2. There is no ...
Table of contents MySQL multi-version concurrency...
Development environment windows Development Tools...
For reference only for Python developers using Ub...
exhibit design Password strength analysis The pas...
As a backend programmer, sometimes I have to tink...
Preface Here are the steps to install and configu...
The nginx.conf configuration file is as follows u...
1. Basic grammar Copy code The code is as follows...
Table of contents Introduction to frm files and i...