做这个跳转页出了点bug 记录下 完美解决 固定公式。
#1 页面框架
<el-pagination
:page-sizes="[2, 4, 6, 8, 10]"
layout="total, sizes, prev, pager, next, jumper"
:page-size="query.pagesize"
:current-page.sync="query.page"
:total="total"
@size-change="changeSize($event)"
@current-change="changeCurrent"
/>
#2 data声明的数据
data() {
return {
query: { // 查询页数
page: 1,
pagesize: 10
},
}
}
#3 点击事件赋值 必须给@current-change赋值 不然跳转页面会有bug
// 重新赋值
this.query.page = Math.ceil(++this.total / this.query.pagesize)
this.changeCurrent(this.query.page)
当在最后一页删除完数据之后表格会显示no date,并不会请求上一页的数据
但如果当前页面还剩 1 条数据,应该请求上一页的数据。
实现代码如下:
if (this.list.length === 1 && this.query.page > 1) {
this.query.page--
}