在<el-table> 组件中添加 属性
:row-class-name="rowClassName" 和 @row-click='handleRowClickRole'
在方法里定义
//获取当前的行数
rowClassName({row, rowIndex}) {
//把每一行的索引放进row
row.index = rowIndex;
// console.log(row)
},
handleRowClickRole(row){
this.rowIndex = row.index
console.log(this.rowIndex)
}
完整如下
<el-table
ref="multipleTable"
:data="tableData"
:row-class-name="rowClassName"
@row-click='handleRowClickRole'
tooltip-effect="dark"
fit
size="medium"
style="width: 100%"
:header-cell-style="{background:'#fafafa'}" >
<el-table-column
prop="bigId"
label="序号"
width="150">
</el-table-column>
</el-table>
<script>
export default {
data() {
return {
tableData: [],
}
},
methods: {
//获取当前的行数
rowClassName({row, rowIndex}) {
//把每一行的索引放进row
row.index = rowIndex;
// console.log(row)
},
handleRowClickRole(row){
this.rowIndex = row.index
console.log(this.rowIndex)
}
}
}
</script>