当前位置:网站首页>2.3 branch statements
2.3 branch statements
2022-07-21 16:05:00 【Qwe7】
2.3 Branch statement
Vue Branch statement in v-if Very easy to understand , Logical heel Java Medium if-else identical .v-if The statement block contains the following :
1.v-if
2.v-else
3.v-else-if
Next, take a simple example to understand :
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<div id="app">
<p v-if="flag">
The weather is very comfortable today !
</p>
<p v-else-if="rich">
It's hot and dry today ! I'm going to relax in the evening !
</p>
<p v-else="rich">
At night, I can only hi !
</p>
</div>
</body>
<script src="https://cdn.bootcss.com/vue/2.6.10/vue.js"></script>
<script>
new Vue({
el:'#app',
data:{
flag:false,
rich:false
},
methods:{
}
});
</script>
</html>
v-if and v-show There seems to be the same effect between , But there are differences in optimization . Let's look at the following example :
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<p v-show="rich">
rich !
</p>
<p v-if="rich">
rich !
</p>
<button type="button" @click="rich=!rich"> Tonight's lottery </button>
</div>
</body>
<script src="https://cdn.bootcss.com/vue/2.6.10/vue.js"></script>
<script>
new Vue({
el:'#app',
data:{
flag:false,
rich:false
},
methods:{
}
});
</script>
</html>
By clicking on “ Tonight's lottery ” Button , Can switch rich Value , At this time, we found that ,v-if and v-show The display status of will switch back and forth . It looks the same , But by looking at the console code ,v-show Will actually p Labeled css Styling display Property set to none To achieve the hidden effect .
and v-if Is to add and delete... Directly on the page p Label to achieve the effect , therefore v-show In the application scenario of repeated switching , Efficient than v-if Higher .
边栏推荐
- 如果没有选中任何线型, CAcUiLineTypeComboBox 崩溃的原因
- [digital image processing / bilateral filtering experiment] high score course experiment report sharing
- 漏洞扫码--需要整改的
- 数据库约束&&MySQL进阶查询
- [dip/ implementation of simple digital image processing system] high score course design paper sharing
- [stc15 controls ws2812 RGB color lamp cascade]
- 小程序毕设作品之微信疫苗预约小程序毕业设计(7)中期检查报告
- vtk9.0.1+Qt5.13手动创建四窗口(MPR+3D)
- What is super app? Applet has four features, you know?
- 利用 vtk 的控件画圆和矩形
猜你喜欢
ESP32-CAM——内网穿透教程
原码、补码以及定点数运算
专注跨境支付一体化服务 iPayLinks荣获《财资》(The Asset)3A亚洲奖!
In depth analysis: how chain 2+1 mode plays with investment attraction and drainage
每日一题-LeetCode1260-二维网格迁移-数组-映射
Daily question-leetcode1260-2d grid migration array mapping
Wechat vaccine appointment applet graduation design of applet completion works (1) development outline
用go tcp实现简单的在线群聊功能
【JS】动态渲染页面
Esp8266 nodemcu - connect WiFi using WiFi manager Library
随机推荐
Set current style dimstyle
小程序毕设作品之微信疫苗预约小程序毕业设计(4)开题报告
Esp8266 nodemcu - connect WiFi using WiFi manager Library
十大券商开户有没有风险的?安全靠谱吗?
Training of head and neck segmentation networks with shape prior on small datasets
Mohist patrol source code
【微信小程序】switch开关选择器(81/100)
如何让localStorage支持过期时间设置?
【愚公系列】2022年7月 Go教学课程 014-运算符之算术运算符
Cluster deployment of Apache Druid 0.22 real-time analysis database on CentOS 7
传统零售企业如何促进消费循环、分享购模式赋能实体企业发展?
CentOS 7上集群化部署Apache Druid 0.22实时分析数据库
conda虚拟环境默认路径如何修改
Cad2014 x64 debugging ARX
CAD2014 X64 调试arx
vtk9.0.1+Qt5.13手动创建四窗口(MPR+3D)
目前最火的测试框架,pytest封神级讲解
如果没有选中任何线型, CAcUiLineTypeComboBox 崩溃的原因
Signal integrity (SI) power integrity (PI) learning notes (xxx) power distribution network (II)
C | array and pointer