美文网首页
mpvue v-for v-if 使用心得

mpvue v-for v-if 使用心得

作者: Neyo_凉 | 来源:发表于2019-04-13 13:30 被阅读0次

vue中 v-for 和 v-if 不要同时使用,需要过滤数组时候可用以下方法过滤

1.可以直接嵌套使用

<div v-for="(item, index) in list"  :key="index"  >
<div v-if="index < 6">
</div>
</div>

2.推荐 用 for循环对象函数【执行过滤后的数组】

<div v-for="(item, index) in ilist"  :key="index"  >
</div>
        ilist () {
          return this.iconList.filter((item, index) => {
            if (index < 6) {
              return 'ture'
            }
          })
        }

相关文章

网友评论

      本文标题:mpvue v-for v-if 使用心得

      本文链接:https://www.haomeiwen.com/subject/odvlwqtx.html