element-ui 中el-pagination组件注意事项

使用 element-ui 中<el-pagination>组件需要注意,在el-pagination组件中开始也是从1开始,但是服务端很多取数据的方法默认是从0开始的,比如:spring data jpa,所以需要处理起始页的索引号,该索引号可以在前端处理,也可以在后端处理:

//服务端分页是从0开始,elementUI 是从1开始,在这里需要减一
    if(currentPage > 0)
      currentPage = currentPage - 1

在页面初始数据绑定是直接使用this.handleCurrentChange(1):

    created(){
       this.handleCurrentChange(1)
       
       //会引起重复取数据
       //this.$store.dispatch("country/getPage")
    },



    handleCurrentChange(val) {
        this.currentPage = val
        this.$store.dispatch("country/setCurrentPage",val)
        this.$store.dispatch("country/getPage")
        console.log(`当前页: ${val}`);
      },    
原文地址:https://www.cnblogs.com/zuxiyo/p/6278612.html