Question: When using element-ui 's table, you will find that the serial number of each page starts from 1, so how can you make it continue the serial number of the previous page?
The index attribute states that if set type=index
, the index can be index
customized by passing attributes
Use computed properties to solve problems:
<el-table-column type="index" :index="hIndex" label="序号" width="120" />
export default {
data() {
return {
page: 1, //当前页数
pagesize: 2, //每页两条数据
}
},
// 计算属性
computed: {
hIndex() {
// 当前页数 - 1 * 每页数据条数 + 1
return (this.page - 1) * this.pagesize + 1
}
}
}
Use functional methods to solve problems
methods: {
hIndex(index) {
// 当前页数 - 1 * 每页数据条数 + index + 1 ( index 是索引值,从0开始)
return (this.page - 1) * this.pagesize + index + 1
}
}