1.v-for优先级要比v-if要高
不能直接这样写,会出现警告。
<div v-for="(item,index) in checkList" :key="index" v-if="item.status">
</div>
正确的写法
<template v-for="(item,index) in checkList">
<div :key="index" v-if="item.status" ></div>
</template>
注意:不要把 v-if 和 v-for 同时用在同一个元素上,带来性能方面的浪费(每次渲染都会先循环再进行条件判断)
2.如果条件出现在循环内部,可通过计算属性computed提前过滤掉那些不需要显示的项
computed: {
items: function() {
return this.list.filter(function (item) {
return item.isShow
})
}
}