element-ui 点击行如何获取table的行索引

文档中有一个tableRowClassName方法,可以获取到当前行的index,
tableRowClassName ({row, rowIndex}) {
      //把每一行的索引放进row
      row.index = rowIndex;
    } 

例子:

表头:

1 <el-table :data="list" v-loading.body="listLoading" element-loading-text="Loading..."  border fit
2                   :row-class-name="tableRowClassName"
3                   @row-click = "onRowClick"
4                   highlight-current-row style="width: 100%">
5                 <el-table-column align="center" prop="passtime" label="Time" width="180">

js:

 1 tableRowClassName ({row, rowIndex}) {
 2       //把每一行的索引放进row
 3       row.index = rowIndex;
 4     },
 5     onRowClick (row, event, column) {
 6       //行点击消除new标记
 7       var index = row.index;
 8       var deleteIndex = Array.indexOf(this.showIndexArr, index);
 9       if (deleteIndex != -1) {
10         this.showIndexArr.splice(deleteIndex,1);  
11       }
12     }

以上。

参考:https://segmentfault.com/q/1010000007849369

posted on 2018-07-11 16:37  临界  阅读(45211)  评论(2编辑  收藏  举报