前端分页方法

前端分页方法

vue或element-ui有的时候tab列表里需要编辑一些东西,使用后台分页是需要调接口的,这个时候你编辑的东西翻页后就不存在了,就需要拿到所有数据后在前端进行分页,数据就不会丢失了,这个时候就可以把编辑后的数据一起传给后台。

this.settlementData这里是接口拿回来的所有数据,

然后table 里data 绑定的值这么写

data 绑定的值 = this.paging(this.pagesize, this.current)

只需要把pagesize和current 传过去就行

paging(pagesize, current) {
/* const tableList = JSON.parse(JSON.stringify(this.tableCopyTableList));*/
const tablePush = []
this.settlementData.forEach((item, index) => {
if (pagesize * (current - 1) <= index && index <= pagesize * current - 1) {
tablePush.push(item)
}
})
return tablePush
}
翻页和改变每页多少条时,在方法里调用

data 绑定的值 = this.paging(this.pagesize, this.current)

只要把拿到的pagesize 和current 传过去即可

老铁们有需要改进的地方可以给我留言

如果您觉得文章有用,可以打赏个咖啡钱

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_43064669/article/details/89330293