根据后台返回的数据写一个分页,通用

// pageIndex ------> 当前页数,也就是页码了

const pageIndex = 1;

// pageSize ------> 这是自定义每页需要展示的条数

const pageSize = 20;

// roundfirmList ------> 这是获取后台返回的总的数据

var roundfirmList = res.data.body;

// tpages ------> 这是获取后台返回的总页数,tCount

const tpages = res.data.page.tCount;

// pages ------> 总数据的条数除以每页需要展示的条数,就是当前页数

const pages = roundfirmList.length/20;

// isInt ------> 如果isInt为1了,就说明数据加载完了

var isInt=tpages/(that.pageIndex*20); 

// 如果页数只有一页或者所有数据加载完了就使loadmore发生改变,根据loadmore可以去设置自己想设置的状态,比如显示“玩命加载中”或者“全部加载完啦”

this.loadmore = (pages==1&&isInt!=1) ? true : false;

// 当前页码不唯一说明有新的数据出现,把新的数据concat进老数据,不要用push,push会改变数组的结构,concat不会

if(that.pageIndex>1){

    this.roundfirm = that.roundfirm.concat(roundfirmList);

}else{

    // 当前页数为第一页,显示数据

    this.roundfirm = roundfirmList;

}

  

原文地址:https://www.cnblogs.com/DangerousBaymax/p/9140896.html