当前位置:网站首页>谈谈v-if显示隐藏问题
谈谈v-if显示隐藏问题
2022-04-23 05:53:00 【Front 小思】
vue条件语句v-if中条件较多时优雅写法
普通写法:
v-if=" type==1 || type==2 || type==3 "
优雅写法:
v-if=" [1,2,3].includes(type) "
更高级写法:
使用方法,复用性高,适用场景:多个标签都需要用到此判断,这样多个标签中的v-if只要用到matchState方法,都可以做判断
注意写法:matchState(某元素,/[匹配值]/)
标签中: v-if="matchState(type,/[123]/)"
方法中: methods: {
// 判断状态
matchState(state = '', reg) {
return !!String(state).match(reg)//返回true/false
}
}
VUE中if条件语句||与&&的使用
1、||与&&同时使用
v-if="!item.type && (item.receiveStatus === 1 || item.receiveStatus === -1 )"
2、只是用||在if条件语句中使用(||条件之间是或者的关系)
v-if="item.coolStorage'–' || item.coolStorage' ' ? flag : !flag"
3、只是用&&在if条件语句中使用(&&两个条件必须一致)
v-if="item.coolStorage'–' && item.coolStorage'' ? flag : !flag"
4、vue 判断某个值是否为真,判断条件为多个值
<button class="action cu-btn" v-if="isContentShow([-1, 3, 4, 7], item.status)" @click.stop="delOrder(item, index)">删除订单</button>
*computed中计算监控:
通常写发:
<div class="item_margin"
v-show="itemList.supplierName || itemList.StoreName || itemList.ContactName || itemList.Phone">
</div>
更美观(最爹)的写法:
<div class="item_margin" v-show="showSupplier"></div>
computed: {
showSupplier () {
return this.itemList.supplierName || this.itemList.supplierStoreName || this.itemList.ContactName || this.itemList.ContactPhone
}
}
版权声明
本文为[Front 小思]所创,转载请带上原文链接,感谢
https://blog.csdn.net/weixin_45788691/article/details/120910347
边栏推荐
- VHDL-任意分频器(50%占空比)
- Running QT program in visual Stdio
- Assembly base code example
- [ThreadX] h743 + ThreadX + Filex migration record
- POJ-The Unique MST
- [UDS unified diagnostic service] II. Network layer protocol (2) - data transmission rules (single frame and multi frame)
- 拷贝构造函数
- 圆整 round 的一点点小细节
- realsense 选型大对比D455 D435i D415 T265 3D硬件对比
- Shell脚本 单引号、双引号和反引号的区别
猜你喜欢
Cross domain issues - allow origin header contains multiple values but only one is allowed
FOC电机库 定点PID代码分析
对象的动态建立和释放,赋值和复制
Call procedure of function
VHDL-任意分频器(50%占空比)
[UDS unified diagnosis service] i. diagnosis overview (2) - main diagnosis protocols (K-line and can)
深蓝学院激光slam 理论与实践 第三章激光雷达去畸变 作业习题
卷积神经网络实现CIFAR100数据集分类
[UDS unified diagnostic service] IV. typical diagnostic service (2) - data transmission function unit
Makefile基础、常用函数及通用Makefile
随机推荐
带默认模板实参的类模板与模板模板形参的匹配
客户端软件增量更新
浮点数双精度,单精度以及半精度知识总结
Camera calibration: key point method vs direct method
在visual stdio中运行qt程序
声明为全局变量
Modify registry values
[UDS unified diagnosis service] i. diagnosis overview (3) - ISO 15765 architecture
[UDS unified diagnostic service] IV. typical diagnostic service (5) - function / component test function unit (routine function unit 0x31)
Notes on advanced points of C language 4
C语言中volatile的使用
Static member
[UDS unified diagnosis service] IV. typical diagnosis service (1) - diagnosis and communication management function unit
CUDA environment installation
realsense 选型大对比D455 D435i D415 T265 3D硬件对比
Collection of practical tips for C language (continuously updated)
C语言实现memcpy、memset、strcpy、strncpy、strcmp、strncmp、strlen
C51/C52 特殊功能寄存器表
基于VGG卷积神经网络的图像识别代码实现
undefined reference to `Nabo::NearestNeighbourSearch