This commit is contained in:
menxipeng
2025-09-13 13:48:40 +08:00
parent 549706f808
commit a14edb27c1
4 changed files with 170 additions and 14 deletions

View File

@@ -81,10 +81,14 @@ export default {
set(val) {
this.$emit('update:limit', val)
}
},
maxPage() {
return Math.ceil(this.total / this.pageSize) || 1
}
},
methods: {
handleSizeChange(val) {
// 当页面大小改变时,检查当前页是否还有效
if (this.currentPage * val > this.total) {
this.currentPage = 1
}
@@ -94,6 +98,16 @@ export default {
}
},
handleCurrentChange(val) {
// 计算最大页数,进行边界检查
const maxPage = Math.ceil(this.total / this.pageSize) || 1;
// 如果请求的页码超出范围,限制在有效范围内
if (val > maxPage) {
val = maxPage;
} else if (val < 1) {
val = 1;
}
this.$emit('pagination', { page: val, limit: this.pageSize })
if (this.autoScroll) {
scrollTo(0, 800)