当前位置:网站首页>User login switching case
User login switching case
2022-07-27 20:56:00 【Yuzhibo Linzhong Road】
1. Definition type
1.1v-if
A small problem :
If we have input , Switched types , We will find that the text still displays the previous input .
But logically , We should switch to another one input The elements are in .
In another input In the elements , We didn't enter anything . Why does this problem arise ?
Problem solving :
This is because Vue It's going on DOM When rendering , For performance reasons , Reuse existing elements as much as possible , Instead of recreating new elements .
In the case above ,Vue The original will be found inside input Element is no longer used , Act directly as else Medium input To use . Solution :
If we don't want Vue There are similar reuse problems , You can give the corresponding input add to key
And we need to make sure key Different
<body>
<div id="app">
<span v-if="type=='username' ">
<label for="username"> The account login :</label>
<input
type="text"
id="username"
placeholder=" The account login "
key="username"
/>
</span>
<span v-else>
<label for="email"> Email login :</label>
<input type="text" id="email" placeholder=" Email login " key="email" />
</span>
<button @click="handleChangeType"> Switch type </button>
</div>
</body>
<script>
const app = new Vue({
el: "#app",
data: {
type: "username",
},
methods: {
handleChangeType() {
this.type = this.type == "username" ? "email" : "username";
},
},
});
</script>1.2.v-show
<body>
<div id="app">
<span v-show="type=='username' ">
<label for="username"> The account login :</label>
<input type="text" id="username" placeholder=" The account login " />
</span>
<span v-show="type=='email' ">
<label for="email"> Email login :</label>
<input type="text" id="email" placeholder=" Email login " />
</span>
<button @click="handleChangeType"> Switch type </button>
</div>
</body>
<script>
const app = new Vue({
el: "#app",
data: {
type: "username",
},
methods: {
handleChangeType() {
this.type = this.type == "username" ? "email" : "username";
},
},
});
</script>2. Define Boolean
2.1 v-if
<body>
<div id="app">
<input type="button" value=" Show login " @click="flag=true" />
<input type="button" value=" Show registration " @click="flag=false" />
<div v-if="flag">
<input type="text" placeholder=" Account " /> <br />
<input type="text" placeholder=" password " /> <br />
<input type="button" value=" Sign in " />
</div>
<div v-else>
<input type="text" placeholder=" user name " /> <br />
<input type="text" placeholder=" Telephone " /> <br />
<input type="button" value=" register " />
</div>
</div>
</body> <script>
const app = new Vue({
el: "#app",
data: {
flag: true,
},
});
</script>
2.2v-show
<body>
<div id="app">
<input type="button" value=" Show login " @click="flag=true" />
<input type="button" value=" Show registration " @click="flag=false" />
<div v-show="flag==true">
<input type="text" placeholder=" Account " /> <br />
<input type="text" placeholder=" password " /> <br />
<input type="button" value=" Sign in " />
</div>
<div v-show="flag == false">
<input type="text" placeholder=" user name " /> <br />
<input type="text" placeholder=" Telephone " /> <br />
<input type="button" value=" register " />
</div>
</div>
</body> <script>
const app = new Vue({
el: "#app",
data: {
flag: true,
},
});
</script>边栏推荐
猜你喜欢
随机推荐
How to calculate the execution time in the function resource usage when using the timer trigger type to process database data?
Nailing development document
RK3399平台开发系列讲解(进程篇)15.36、理解进程和协程
Kingbasees heterogeneous database migration guide (2. Overview)
Go --- automatic recompilation of air
人脸识别5.1- insightface人脸检测模型训练实战笔记
go --- air自动重新编译
[hierarchical reinforcement learning] HAC paper and code
Tencent jumped out with 38K and saw the real test ceiling
What configurations are required to connect polardb and redis?
JVS私有化部署启动失败处理方案
openresty lua-resty-core 使用
金仓数据库 Oracle 至 KingbaseES 迁移最佳实践 (4. Oracle数据库移植实战)
Where is the program?
【深度学习】Pytorch Tensor 张量
[dataset display annotation] VOC file structure + dataset annotation visualization + code implementation
一文了解Pycharm快捷键
Management of user organization structure
The variable "lattice" or class "lattice.latticeeasy" (matlab) is not defined
R语言使用epiDisplay包的lroc函数可视化logistic回归模型的ROC曲线并输出诊断表(diagnostic table)、可视化多条ROC曲线、使用legend函数为可视化图像添加图例




![[efficiency] abandon notepad++, this open source substitute is more awesome!](/img/41/495bbe4d1e6d953ba5c4d8984f81e7.jpg)





