<template>
<el-table @selection-change="handleSelectionChange" :row-key="getRowKeys">
<!--type必须是selection的一列设置reserve-selection属性-->
<el-table-column type="selection" :reserve-selection="true" width="40" align="center"></el-table-column>
<el-table-column props="name" align="center"></el-table-column>
</el-table>
</template>
<script>
export default {
data: {
selection:[{name: '张三', id: 1}, {name: '李四', id: 2}]
},
methods: {
handleSelectionChange (val) {
this.selection = val;
},
getRowKeys (row) {
return row.id; // id为列表数据的唯一标识
}
}
}
</script>