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

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

例子:

表头:

1 "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                 "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

转载于:https://www.cnblogs.com/yangyi9343/p/9295293.html

你可能感兴趣的:(element-ui 点击行如何获取table的行索引)