iView - table 解决分页后跳转到其它页,序号还是从1开始的问题

不分页的情况下,可以type="index";

data() {
  return {
    tableColumn: [{type: 'index', width: 70, align: 'center', title: '序号'}]
  }
}

分页的情况下,有两种方式:

方式一:在data中定义列表项时赋值

data() {
  return {
      tableColumn: [{
          width: 70,
          align: 'center',
          title: '序号',
          render: (h,params) => {
                return h('span', params.index + (this.searchCondition.pageNum -1) * this.searchCondition.pageSize + 1)
          }
       }]
    }
}

方式二:在接口返回的数据中增加索引值

data() {
  return {
      tableColumn: [{key: 'index',width: 70,align: 'center',title: '序号'}]
    }
},
methods: {
    async getWorldWideList() {
      let res = await API.getWorldWideListApi(this.searchCondition)
      if (res.data.success) {
        res.data.data.list = res.data.data.list.map((item, index) => {
          return {...item, ...{index: index + (this.searchCondition.pageNum -1) * this.searchCondition.pageSize + 1}}
        })
        this.tableData = res.data.data.list
        this.pagination.total = res.data.data.total
        this.pagination.currentPage = res.data.data.pageNum
      }
    }
}

 

 

 

你可能感兴趣的:(iView,vue,iView-table)