前端分页实现
// 前端分页功能
// array需要分页的数组, page 当前页码, size 一页的条数
const customPagingFunc = (array, page, size) => {
if (page === 0) page = 1
// 用slice截取数组要显示的内容,不改变原数组
return array.slice((page - 1) * size, page * size)
}
// 分页
tablePaging () {
let keepTableList = []
keepTableList = JSON.parse(JSON.stringify(this.keepTableData))
this.tableData = []
this.total = keepTableList.length
// 当页数据全部删除后,页面未跳转至前一页
if (customPagingFunc(keepTableList, this.page, this.pageSize).length === 0 && this.page > 1) {
this.page--
}
this.tableData = customPagingFunc(keepTableList, this.page, this.pageSize)
this.loading = false
},