You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

不使用第三方库的Vue表格上下页分页功能失效问题咨询

Vue 原生表格分页修复方案

核心问题

计算属性quotesPerPage的slice方法固定从索引0开始截取数据,因此无论currentPage如何变更,永远只会返回前15条数据,导致分页切换无效果。

修复步骤

1. 修改分页计算属性逻辑

动态计算每页数据的截取起始、结束下标:

computed: {
  quotesPerPage() {
    const startIndex = this.currentPage * this.rowsPerPage
    const endIndex = startIndex + this.rowsPerPage
    return this.quotes.slice(startIndex, endIndex)
  }
}

2. 可选:简化分页切换逻辑

原有切换逻辑可删除冗余的无效赋值,下页判断逻辑用总页数计算更直观:

nextButton() {
  const totalPage = Math.ceil(this.quotes.length / this.rowsPerPage)
  // 页码从0开始,最后一页的页码为总页数-1
  if (this.currentPage < totalPage - 1) {
    this.currentPage += 1
  }
},
previousButton() {
  if (this.currentPage > 0) {
    this.currentPage -= 1
  }
}

注意事项

  • 初始化时要给currentPage设置默认值0,rowsPerPage设置默认值15
  • 如果quotes是异步请求获取的数据源,数据更新后要判断当前currentPage是否超过新数据的最大页码,超过则重置currentPage为0,避免出现空页

内容的提问来源于stack exchange,提问作者tony

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.01 04:39:03