当前位置:网站首页>当v-if和v-for需要同时使用的时候
当v-if和v-for需要同时使用的时候
2022-06-10 16:17:00 【一粒程序米】
当使用v-for的时候需要选择性地隐藏部分item
本来的错误写法是这样:
<div class="card-view-item" v-for="(item,index) in cardList" :key="index" v-if="item.show"> </div>
在data里声明的cardList
cardList:[
{
title:'夜间睡眠',
time:'12/1',
show:true,
},
{
title:'步数和热量',
time:'12/1',
show:false,
},
]
以上的那种用法是错误的。v-for的优先级是高于v-if的,如果两者同时使用,那么v-if会在每一个v-for循环渲染出来的项上作用,造成性能上的浪费。
下面是正确用法:
我们可以利用computed:
computed: {
activeItemList: function() {
return this.cardList.filter((item) => {
return item.show
})
}
}
<div class="card-view-item" v-for="(item,index) in activeItemList" :key="index" > </div>
这样就可以了
边栏推荐
- Carry forward the past and forge ahead into the future, multiple residuals | densenet (II)
- Calling subroutines from other modules in VBA - call a subroutine from a different module in VBA
- Fabric. Keep the original level when JS element is selected
- VBA判断文件是否存在及问文件备份思路
- Fabric.js 精简输出的JSON
- 复利最高的保险产品是什么?一年要交多少钱?
- How does Dao achieve decentralized governance?
- [web security self-study] section 1 building of basic Web Environment
- Fabric. JS lock the background image, not affected by zooming and dragging
- Pictographic dynamic graphic ideographic data
猜你喜欢

智慧景区视频监控 5G智慧灯杆网关组网综合杆

解决idea打开某个项目卡住的问题

成立1年便成独角兽,腾讯滴滴做「靠山」,今年新晋的独角兽不简单

Smart Scenic Spot Video Monitoring 5G Smart lamp Gateway Network Integrated pole

全链路追踪 & 性能监控工具 SkyWalking 实战

Mm main tables and main fields_ SAP LIUMENG_

Carry forward the past and forge ahead into the future, multiple residuals | densenet (I)

提升园区服务水平,优化营商环境该从哪些方面入手

Detailed steps for installing redis image in docker (easy to understand, suitable for novices to get started quickly)

ADB is not an internal or external command, nor is it a runnable program or batch file
随机推荐
Fabric.js 元素被选中时保持原有层级
Fabric.js 激活输入框
Simple site backup shell script
How does Dao achieve decentralized governance?
Nat. Commun. | 用于加速发现抗生素抗性基因的知识整合和决策支持
智慧景區視頻監控 5G智慧燈杆網關組網綜合杆
VBA divides strings, stores them in an array, writes them to a file, and saves them
Pictographic dynamic graphic ideographic data
Knowledge based bert: a method to extract molecular features like a computational chemist
大山深处的孩子,正在看见更远的星空
新思科技在《 2022 年 Gartner 应用安全测试关键能力报告》中表现优异 在五个常见用例中荣获最高分
Calling subroutines from other modules in VBA - call a subroutine from a different module in VBA
关于透视投影变换及相关应用的详细推导
一文带你了解J.U.C的FutureTask、Fork/Join框架和BlockingQueue
Technology sharing | quick intercom, global intercom
Numpy learning notes
What should be done to improve the service level of the park and optimize the business environment
隐形马尔可夫模型及其训练(一)
ADB is not an internal or external command, nor is it a runnable program or batch file
二十多年了,安全套市场还只有杜蕾斯、冈本、杰士邦