代码放在获取列表的接口代码中,每次删除执行完,获取一下列表代码,假设获取列表数据的方法是getData()
// 这是 getData()中获取数据成功后的代码
if (res.code == 200) {
this.intellStationData = res.data.list;
this.dataCount = res.data.totalCount;
// ==================================有用代码-star===============================
// 获取列表数据的方法 getData()
// 当前页是第几页 currentPage
// 列表数据总条数 dataCount
// 每页展示多少条 pageSize
// 总共多少页 pageCount 默认为1
this.pageCount = Math.ceil(Number(this.dataCount) / Number(this.pageSize))
//当前页大于总页数代表已经删除最后一条数据 将总页数赋值给当前页 会跳转到上一页
let crpage = this.currentPage > this.pageCount ? this.pageCount : this.currentPage
if(this.currentPage != crpage){
this.currentPage = crpage
this.getData()
}
//当页数小于为1 就给它为1页 否则就还是当前页
this.currentPage = this.currentPage < 1 ? 1 : this.currentPage
// ==================================有用代码-end================================
} else {
this.intellStationData = [];
this.dataCount = 0;
}