文档中有一个tableRowClassName方法,可以获取到当前行的index
在表头加入:row-class-name="tableRowClassName",在方法中定义tableRowClassName
表头:
<el-table
:data=""
:row-class-name="tableRowClassName"
highlight-current-row
stripe
@current-change="selectChange"
>
js:
tableRowClassName({ row, rowIndex }) {
// 把每一行的索引放进row
row.index = rowIndex
},
selectChange(val) {
this.currentRow = val
},
deleteGood() {
this.createInvoiceForm.selectGoods.splice(this.currentRow.index, 1)
this.calculations()
},
没有调用tableRowClassName方法之前currentRow对象是没有index属性的,调用方法之后就有了index属性,可以通过这个获取索引进行操作