当前位置:网站首页>当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>
这样就可以了
边栏推荐
- Institute of automation, Chinese Academy of Sciences: a review of the latest visual language pre training
- AHK common functions
- 6. Mgr status monitoring | Mgr in simple terms
- Shit, jialichuang's price is reduced again
- From web2 to Web3, ideology also needs to change
- Richard Behrman, the founder of dynamic planning
- B站不想成为“良心版爱优腾”
- Xinsi technology performed well in the Gartner application security test key capability report 2022 and won the highest score among the five common use cases
- Fail fast and fail safe
- AlphaFold 和 NMR 测定溶液中蛋白质结构的准确性
猜你喜欢

大山深处的孩子,正在看见更远的星空
![[web security self-study] section 1 building of basic Web Environment](/img/f8/f2d13c2879cdbc03ad261c6569bc1d.jpg)
[web security self-study] section 1 building of basic Web Environment

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

Li Ling: in six years, how did I go from open source Xiaobai to Apache top project PMC

Pictographic dynamic graphic ideographic data

Under the "plastic ban order", does the Hong Kong stock exchange pay for the deep excavation of degradable plastics by Zhongbao new materials?

Live broadcast preview | a new era of social interaction, exploring new social experiences in the universe

postman参数化

Shit, jialichuang's price is reduced again

Institute of automation, Chinese Academy of Sciences: a review of the latest visual language pre training
随机推荐
AlphaFold 和 NMR 测定溶液中蛋白质结构的准确性
互联网企业与芯片
用代码设计药物:我们到了吗?
From web2 to Web3, ideology also needs to change
L1-069 tire pressure monitoring (15 points)
复利最高的保险产品是什么?一年要交多少钱?
Carry forward the past and forge ahead into the future, multiple residuals | densenet (II)
Fabric.js 元素被选中时保持原有层级
Example code of PHP for uploading multiple pictures
College entrance examination that year
How to make a simple Snake game with pyGame
What is the highest compound interest insurance product? How much does it cost a year?
Who is using my server? what are you doing? when?
Do you know the five GoLand shortcuts to improve efficiency?
直播预告 | 社交新纪元,共探元宇宙社交新体验
MFC基础知识与课程设计思路
谁在使用我的服务器?在干什么?什么时候?
智慧景區視頻監控 5G智慧燈杆網關組網綜合杆
NumPy 学习笔记
Xinsi technology performed well in the Gartner application security test key capability report 2022 and won the highest score among the five common use cases