当前位置: 移动技术网 > IT编程>开发语言>JavaScript > element表格翻页第2页从1开始编号(后端从0开始分页)

element表格翻页第2页从1开始编号(后端从0开始分页)

2020年03月09日  | 移动技术网IT编程  | 我要评论

项目中常见的分页显示,第二页从1开始编号,然后在切换分页的过程中,偶现不对,都是小问题,整理记录一下,供参考。
template:

...
<el-table-column 
type="index" 
label="编号"
:index="getindex"
width="80px">
 </el-table-column>
...
<pagination
  :total="total"
  :pagesize="pagesize"
  :currentpage="currentpage"
  @sizechange="sizechange"
  @currentchange="currentchange">
</pagination>

script:

 getindex (index) {
  if (this.currentpage==0){
    return (this.currentpage) * this.pagesize + index + 1
  } else{
    return (this.currentpage-1) * this.pagesize + index + 1
  }
 },

由于后端第一页是从0开始的,而前端是从第一页开始,所以需要在当前页减1。关于分页,本页条数

sizechange(val){
  let that = this;
  that.currentpage = 1;
  that.pagesize = val;
  that.getpageinfo(that.currentpage, val);
},

跳转页面

currentchange(val){
  let that = this;
  that.currentpage = val;
  that.getpageinfo(val, that.pagesize);
},

页面加载数据

getuserlist(currentpage, pagesize){
  let that = this;
  that.$axios({
   method: 'get',
   url: '***',
   params: {
    currentpage: (currentpage || that.currentpage || 1)-1,
    pagesize: pagesize || that.pagesize || 10
   },
   needinterceptors: true,
   showerror: true,
   loader: true
  }).then(function(result){
   let data = result && result.data || [];
   let page = result && result.pagecont || {};
   that.total = page.totalitems || 0;
   that.tabledata = data;
  })
 },

试了几次,这样写应该是没有问题的,也解决了后端传0开始的问题。

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持移动技术网。

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网