公告:魔扣目录网为广大站长提供免费收录网站服务,提交前请做好本站友链:【 网站目录:https://www.morko.net 】, 免友链快审服务(50元/站),

点击这里在线咨询客服
新站提交
  • 网站:51998
  • 待审:31
  • 小程序:12
  • 文章:1030137
  • 会员:747

实现效果:假如有10条数据,分组展示,默认在当前页面展示4个,点击换一批,从第5个开始继续展示,到最后一组,再重新返回到第一组

 

VUE:在VUE中实现效果"换一换"功能

 

data() {
    return {
      qList: [],
      //处理后的list
      newList: [],
      //截取第几组的开始参数
      timeStart: 0,
      //截取第几组的结束参数
      timeEnd: 1,
      //默认为0组
      group: 0,
      //一页展示list数量
      num: 3,
      //点击的次数
      clickNum: 0
    };
  },
<div class="flex-align" @click="change">
        <span>换一批</span>
      </div>
// 换一批
    change() {
      if (this.qList.length > 4 && this.qList.length > this.num) {
        //点击的时候获取分为几组
        this.listlen();
        //每点击一次记录点击次数
        this.autoIncre();
        this.clear();
        this.renderR();
      }
    },
    // 计算数据的长度,共分为几组,如果不能整除则加1
    listlen() {
      var len = this.qList.length;
      this.group = len / this.num;
      if (len % this.num != 0) {
        this.group = parseInt(this.group) + 1;
      }
    },
    //计算将点击次数和开始截取的参数清空, 如果点击此时大于当前数据的组数,则重新开始计数。
    clear() {
      if (this.clickNum > this.group - 1) {
        this.timeStart = 0;
        this.timeEnd = 1;
        this.clickNum = 0;
      }
    },
    //每点击一次,记录次数
    autoIncre() {
      this.clickNum++;
      this.timeStart++;
      this.timeEnd++;
    },
    //截取当前每组的数据
    renderR() {
      this.newList = this.qList.slice(
        this.num * this.timeStart,
        this.num * this.timeEnd
      );
      console.log(this.newList);
    }
  },
  
//获取总数据
  created() {
    let params = {
      keyword: ""
    };
    this.$https("get", "/xxx/xxx", params)
      .then(res => {
        var data = res.data.data;
        this.qList = data;
        this.renderR();
      })
      .catch(err => {
        
      });
  }

分享到:
标签:VUE
用户无头像

网友整理

注册时间:

网站:5 个   小程序:0 个  文章:12 篇

  • 51998

    网站

  • 12

    小程序

  • 1030137

    文章

  • 747

    会员

赶快注册账号,推广您的网站吧!
最新入驻小程序

数独大挑战2018-06-03

数独一种数学游戏,玩家需要根据9

答题星2018-06-03

您可以通过答题星轻松地创建试卷

全阶人生考试2018-06-03

各种考试题,题库,初中,高中,大学四六

运动步数有氧达人2018-06-03

记录运动步数,积累氧气值。还可偷

每日养生app2018-06-03

每日养生,天天健康

体育训练成绩评定2018-06-03

通用课目体育训练成绩评定