当前位置:网站首页>谈谈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
边栏推荐
猜你喜欢
[UDS unified diagnosis service] i. diagnosis overview (1) - diagnosis overview
VHDL-任意分频器(50%占空比)
[ThreadX] ThreadX source code reading plan (I)
函数的调用过程
【UDS统一诊断服务】(补充)五、ECU bootloader开发要点详解 (2)
【UDS统一诊断服务】一、诊断概述(1)— 诊断概述
CUDA environment installation
Cross domain issues - allow origin header contains multiple values but only one is allowed
浮点数双精度,单精度以及半精度知识总结
FOC SVPWM函数PWMC_SetPhaseVoltage解析
随机推荐
Wechat applet request encapsulation
OpenCV使用 GenericIndex 进行 KNN 搜索
Latex configuration and use
[stepping on the pit] MELD in win11 wsl2 cannot be used normally. Problem repair
Installation of GCC, G + +, GDB
CUDA environment installation
[UDS unified diagnostic service] i. overview of diagnosis (4) - basic concepts and terms
Initialization of classes and objects (constructors and destructors)
深蓝学院激光slam理论与实践 -第二章(里程计标定)作业
记第一次使用阿里字体图标库
浮点数双精度,单精度以及半精度知识总结
HDU-Tunnel Warfare
realsense 选型大对比D455 D435i D415 T265 3D硬件对比
[ThreadX] h743 + ThreadX + Filex migration record
Quaternion multiplication
Multibyte and Unicode in VS
在visual stdio中运行qt程序
Interprocess communication - mutex
搭建jpress个人博客
POJ-The Unique MST