第一种方法:将index放到row数据中
首先,给table加一个属性::row-class-name="tableRowClassName"
然后定义tableRowClassName函数:(tableRowClassName可以自己改名)
tableRowClassName({row, rowIndex}) {row.row_index = rowIndex;}
然后给表格添加: @row-click = "onRowClick"
onRowClick (row, event, column) {this.currentRowIndex = row.row_index;}
这时,属性:currentRowIndex存的就是当前选中行的index了
el table表格中用了select怎么获取,选择行对象
el table表格中用了select怎么获取,选择行对象,为什么我下面会undefined
事件名 说明 参数
select 当用户手动勾选数据行的 Checkbox 时触发的事件 selection, row
<el-table ref="singleTable" @select='selectCall()' :data="tableData" highlight-current-row style="width: 97%">
<el-table-column type="selection" width="55"></el-table-column>
<el-table-column property="code" label="属性编码" width="120" > </el-table-column>
<el-table-column property="name" label="属性名称" width="120"> </el-table-column>
<el-table-column property="unit" label="数量"></el-table-column>
<el-table-column property="unit" label="单位"></el-table-column>
</el-table>
selectCall(row){
console.log(row);//undefined
}
本文介绍如何在 Element UI 的 el-table 组件中通过自定义 row-class-name 函数将行索引附加到数据行,并在点击行时获取该索引。同时,解决使用 select 事件时选择行对象返回 undefined 的问题。
2061

被折叠的 条评论
为什么被折叠?



