vue中v-if和v-for指令最好不要同时使用的解决方法

建议不要在与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
      })
    }
  },
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值