element表格设置序号

  • Post author:
  • Post category:其他


方法一:在js中添加

1.在template中

<el-table-column prop="index" label="序号" width="55" align="left"></el-table-column>

2.在方法中

 // 添加序号
this.tableData.map((item, index) => {
     item.index = this.tableListQuery.limit * (this.tableListQuery.page - 1) + (index + 1);
     if (index === 0) {
         this.curStartTerIndex = this.tableListQuery.limit * (this.tableListQuery.page - 1) + (index + 1);
      }
     if (index === this.tableData.length - 1) {
         this.curEndTerIndex = this.tableListQuery.limit * (this.tableListQuery.page - 1) + (index + 1);
     }
     return item;
});

方法二:利用分页特性,直接在el-table-column列中添加(推荐)

<el-table-column label="序号" type="index" align="center" width="67">
    <template slot-scope="scope">
        <span>{{(tableParam.page - 1) * tableParam.limit + scope.$index + 1}}</span>
    </template>
</el-table-column>



版权声明:本文为cqqorcq原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。