vue v-for list数据循环 每3或者(n)个一组

template

<van-swipe class="my-swipe-list" :autoplay="3000" indicator-color="#067EEA">
            <van-swipe-item v-for="(item,index) in listTemp" :key="index">
                <van-row>
                  <van-col :span="8" v-for="(cell,i) in item" :key="i">
                    <img :src="cell.pic" alt="">
                    <p v-html="cell.title">{{cell.title}}</p>
                    <p>{{cell.content}}</p>
                  </van-col>
                </van-row>
            </van-swipe-item>
        </van-swipe>

  

computed代码

computed:{
          listTemp:function(){
            let index =0;
            let count = 3;
            let arrTemp = [];
            let experts = this.experts;
            for(let i=0;i<this.experts.length;i++){
              index = parseInt(i/count);
              if (arrTemp.length <= index) {
                  arrTemp.push([]);
              }
              arrTemp[index].push(experts[i])
            }
            return arrTemp
          }
        }

  

 

posted on 2020-02-28 19:48  小武爷  阅读(14345)  评论(1编辑  收藏  举报