自动翻页效果,每页展示特定条,每10s翻页一次数据

1. 方法一

原先结构
在这里插入图片描述
改成结构
在这里插入图片描述

 initAxios(url) {
      this.$axios.get(url).then((response) => {
        let json = response.data.Data //获取到的数据
        let show = json;
        var groupSize = 13; //每页显示13个数据
        var newgroup = [];
        var tempGroup = [];
        let currentIndex=0
        show.forEach(item => {
          tempGroup.push(item);
          if (tempGroup.length === groupSize) {
            newgroup.push(tempGroup)
            tempGroup = []
          }
        });
        if (tempGroup.length > 0) {
          newgroup.push(tempGroup);
        }
        //上面是把数组分成  [[],[],[]] 这样的结构,如图所示
        this.listData=newgroup[currentIndex]
        this.b=setInterval(()=>{
          currentIndex = (currentIndex + 1) % newgroup.length;
          this.listData=newgroup[currentIndex]
        },10*1000)
      })
    },

2. 方法二

  // 列表
        common.ajaxTwo('Get','url').then(res=>{
          if(res.Code==0){
            this.listData=res.Data1
            this.indexOne=0
            this.singleShow()
          }
        })

  change(num) {
        this.showListData = [];
        let index = 0;
        if (this.indexOne === this.listData.length) {
          this.indexOne = 0;
        }
        for (let i = this.indexOne; i < this.indexOne + num; i++) {
          if (this.listData[i]) {

            this.showListData.push(this.listData[i]);
            index = i;
          }
        }
        this.indexOne = index + 1;
      },
  singleShow() {
        this.change(5)
        // 单纯展示
        this.a = setInterval(() => {
          this.change(5)
        }, 5000)
      },
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值