建议不要在与v-for相同的元素上使用v-if。因为v-for指令的优先级高于v-if当它们处于同一节点。v-for 的优先级比 v-if 更高,这意味着 v-if 将分别重复运行于每个 v-for 循环中。
<div class="application-list" v-for="(items,index) in applicationListaa" :key="index">
<div class="application-totle row items-center">
<div></div>
<p>{{items.name}}</p>
</div>
<div class="row children-list">
<div class="col-3 text-center children-list-one" v-for="(item,i) in items.childrenApply" :key="i">
<img :src="item.actUrl" alt="" srcset="">
<p>{{item.title}}</p>
</div>
</div>
</div>
1将if指令添加到父级元素上,这可以避免对每个列表项进行条件判断。
如果需要在列表中过滤掉不需要的某一项,建议使用计算属性。
data() {
return {
text: '',
websock: null,
applicationLists:[
{
id:1,
name:'我的应用',
isShow:true,
childrenApply:[
{
id:1,
title:'待阅文件',
actUrl:'../../statics/images/icon/wjjh.png',
badge:0
},
{
id:2,
title:'钉邮',
actUrl:'../../statics/images/icon/wjjh.png',
badge:1
},
{
id:3,
title:'钉盘',
actUrl:'../../statics/images/icon/wjjh.png',
badge:1
},
{
id:4,
title:'智能表单',
actUrl:'../../statics/images/icon/wjjh.png',
badge:1
},
{
id:2,
title:'会议室预定',
actUrl:'../../statics/images/icon/wjjh.png',
badge:1
},
]
},
{
id:2,
name:'特色应用',
isShow:false,
childrenApply:[
{
id:1,
title:'待阅文件',
actUrl:'../../statics/images/icon/wjjh.png',
badge:5
},
{
id:2,
title:'钉邮',
actUrl:'../../statics/images/icon/wjjh.png',
badge:88
}
]
},
{
id:3,
name:'协程办公',
isShow:true,
childrenApply:[
{
id:1,
title:'待阅文件',
actUrl:'../../statics/images/icon/wjjh.png',
badge:99
},
{
id:2,
title:'钉邮',
actUrl:'../../statics/images/icon/wjjh.png',
badge:88
}
]
},
],
};
},
computed: {
applicationListaa() {
return this.applicationLists.filter(function (item) {
return item.isShow
})
}
},