1.在el-table中添加行标识 :row-key="val => val.id",这里最好选择能唯一标识每一行的数据作为key的返回值,否则回选失败
<el-table :row-key="val => val.id" :data="tableList" border style="width: 100%" @selection-change="handleSelectionChange">
2.在复选框那列加上这个属性:reserve-selection="true"
<el-table-column :reserve-selection="true" type="selection" width="55"></el-table-column>
完整代码:
#html:
<el-table :row-key="val => val.id" @selection-change="handleSelectionChange" :data="tableList">
<el-table-column type="selection" :reserve-selection="true" width="55" />
</el-table>
#js:
<script>
export default {
data() {
return {
selExpertList:[],
};
},
methods: {
handleSelectionChange(selection) {
this.selExpertList = JSON.parse(JSON.stringify(selection));
},
},
};
</script>