This article example shares the specific code of Vue to realize user login switching for your reference. The specific content is as follows Switching has problems Code <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> <div id="app"> <span v-if="isUser"> <label for="username">User Account</label> <input type="text" id="username" placeholder="User account"> </span> <span v-else> <label for="email">User mailbox</label> <input type="text" id="email" placeholder="User email"> </span> <button @click="isUser = !isUser">Switch type</button> </div> <script src="../js/vue.js"></script> <script> const app = new Vue({ el: '#app', data: { isUser: true } }) </script> </body> </html> Effect display Problems
Why does this problem occur? This is because when Vue renders the DOM , for performance reasons, it will reuse existing elements as much as possible instead of creating new elements. Solution
Perfect version login example Add different keys in input Code <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> <div id="app"> <span v-if="isUser"> <label for="username">User Account</label> <input type="text" id="username" placeholder="User account" key="username"> </span> <span v-else> <label for="email">User mailbox</label> <input type="text" id="email" placeholder="User email" key="email"> </span> <button @click="isUser = !isUser">Switch type</button> </div> <script src="../js/vue.js"></script> <script> const app = new Vue({ el: '#app', data: { isUser: true } }) </script> </body> </html> Effect display The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. You may also be interested in:
|
<<: Detailed explanation of redundant and duplicate indexes in MySQL
>>: Detailed explanation of the role of explain in MySQL
To achieve CSS screen size adaptation, we must fi...
max_allowed_packet is a parameter in MySQL that i...
MySQL creates users and authorizes and revokes us...
To create a flex container, simply add a display:...
Table of contents (1) Introduction: (2) The ways ...
The specific code of JavaScript date effects is f...
Table of contents 1. Form events 2. Mouse events ...
1 Background Recently, I have been studying how t...
This article shares the specific code of the WeCh...
This article shares the 6 most effective methods,...
Table of contents 1. Effect 2. Main code 1. Effec...
Table of contents Preface question Online solutio...
In the horizontal direction, you can set the cell...
Table of contents 1- Error details 2-Single Solut...
Table of contents Preface Setting up with Vue CLI...