其他分享
首页 > 其他分享> > vue v-for list数据循环 每3或者(n)个一组

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
          }
        }

  

 

标签:function,content,vue,computed,一组,list,cell,let,experts
来源: https://www.cnblogs.com/junwu/p/12378771.html