列表最后一页删除末页最后一条时,自动跳转到上一页并获取上一页数据

代码放在获取列表的接口代码中,每次删除执行完,获取一下列表代码,假设获取列表数据的方法是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;
}
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值