- 如何获取到 ElementUI 中 表格(table) 组件前 多选框被选中后的id数组呢?
- 使用 table 组件的@selection-change事件监听当多选框被选中时的动作,获取到当前被选中的对象,将对象中的id取出之后放到新的数组中即可。
<el-table
ref="multipleTable"
:data="merchantManage"
tooltip-effect="dark"
style="width: 100%"
@selection-change="tableSelected">
data () {
return {
this.isDelBatchMerchantBtn
}
}
/**
* 获取表格多选 选中的商家信息
*/
tableSelected (val) {
// 去重获取被选中的id值存入到数组中
for (let selectedItem of val) {
this.merchantSelectedIds.push(selectedItem.id)
}
// 选中多选之后 删除选中按钮修改为可用状态
this.isDelBatchMerchantBtn = !this.isDelBatchMerchantBtn
}