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
All tags must be lowercase In XHTML, all tags must...
Environment: MacOS_Cetalina_10.15.1, Mysql8.0.18,...
Table of contents Port-related concepts: Relation...
Table of contents 1. js memory 2. Assignment 3. S...
"Development is more than just writing code&q...
<br /> CSS syntax for table borders The spec...
Author | Editor Awen | Produced by Tu Min | CSDN ...
I found a lot of websites that use drop-down or sl...
Find the problem I recently encountered a problem...
Table of contents 1. Back up the old MySQL5.7 dat...
Table of contents question Solution question Ther...
When using the docker-maven-plugin plug-in, Maven...
Preface This article mainly introduces the releva...
Table of contents 1. Create a Hadoop directory in...
Table of contents Problem Description The general...