el-pagination 后端接口分页页数从0开始

这篇博客主要介绍了在前端应用中使用`el-pagination`组件实现分页功能,包括页面大小切换和当前页变更的处理方法。`handleCurrentChange`和`handleSizeChange`函数分别用于更新请求参数并重新获取表格数据。在调用后台接口`dictListAPI`时,注意要将页数减1以适应后台的分页逻辑。博客还展示了如何绑定数据到表格,并展示了响应式加载数据的流程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 <el-pagination
        background
        layout="total, prev, pager, next"
        :current-page="searchForm.page"
        :page-sizes="[10, 20, 30, 40, 50]"
        :page-size="searchForm.size"
        :total="total"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />
  data() {
    return {
      searchForm: {
        page: 1,
        size: 10
      },
    // 换页
    handleCurrentChange: function(val) {
      this.searchForm.page = val
      this.getTableData()
    },
    // 每页显示数量
    handleSizeChange: function(val) {
      this.searchForm.size = val
      setTimeout(() => { this.getTableData() }, 0)
    },
    // 获取页面表格
    getTableData: function() {
      const params = Object.assign({}, this.searchForm)
      params.page = params.page - 1  // **给后台的page参数,进行减1**
      API.dictListAPI(params).then(response => {
        const res = response
        if (res.code === '200') {
          this.tableData = res.data.content
          this.total = res.data.total
        } else {
          this.$errorMsg(res.errmsg)
        }
      }).catch(error => {
        this.$errorMsg('' + error)
      })
    }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值