赞
踩
<el-table @row-click="handleRowClick">
</el-table>
...
methods: {
handleRowClick(row, event, column) {
const rowIndex = event.target.parentNode.rowIndex - 1;
...
}
}
请注意,在处理handleRowClick方法时,我们需要计算出所点击的行在el-table数据数组中的位置,这里使用了event.target.parentNode.rowIndex-1来获取其索引值。
使用element-ui中的slot-scope属性,将每一行的索引传递给自定义列组件中的方法
<el-table-column label="操作">
<template slot-scope="scope">
<el-button @click="handleClick(scope.$index)">点击</el-button>
</template>
</el-table-column>
...
methods: {
handleClick(rowIndex) {
...
}
}
$index
(表示当前行的索引)传递给了自定义列组件中的模板。这里我们直接将$index
作为方法参数传入即可得到所点击的行的索引。Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。