<el-pagination
background
:current-page.sync="pagination.currentPage"
:page-size="pagination.pageSize"
layout="prev, pager, next , jumper"
:total="total"
@current-change="">
</el-pagination>
data() {
return {
pagination:{
pageSize:10,
currentPage:1
}
}
}
// 向后端发送新增数据请求
// 新增成功后
this.pagination.currentPage = Math.ceil(++this.total / this.pagination.pageSize)
// 在上一行更新好当前页码后,此处再请求后端获取当前页码的数据,即可跳转到最后一页
重点:
1. :current-page.sync 中的 sync 标志 2. 给this.pagination.currentPage赋新值 3. ++this.total
我这里表格内容跳到最新页了,但是分页器一直显示在倒数第二页。
后来发现是this.total未更新,我原来写成
this.pagination.currentPage = Math.ceil(this.total+1 / this.pagination.pageSize)
这样this.total还是原来的值,但写成++this.total ,this.total会加1。