从tableData中的数据可以看到id并不是唯一的,其中也没有任何一个字段是唯一标识,那么这种情况row-key="id"这样写就会导致我勾选的数据出现错乱,这时候把row-key="id"改成:row-key="tableData=>tableData.id+tableData.type" 就好了
<template>
<el-table ref="table" :data="tableData" border highlight-current-row :row-key="tableData=>tableData.id+tableData.type" @selection-change="selectionChange">
<el-table-column type="selection" reserve-selection width="55"></el-table-column>
<el-table-column align="center" label="编号" width="60" type="index">
</el-table-column>
<el-table-column prop="id" label="ID" align="center" />
<el-table-column prop="type" label="类型" align="center" />
</el-table>
</template>
<script>
export default {
components: {
},
data() {
return {
multipleSelection: [],
tableData: [
{
id: 0,
type: 'A'
},
{
id: 1,
type: 'A'
},
{
id: 2,
type: 'A'
},
{
id: 0,
type: 'B'
},
{
id: 1,
type: 'B'
}
]
}
},
mounted() {
},
methods: {
selectionChange(val) {
this.multipleSelection = val
}
}
}
</script>