我怀疑val[0].Id是没有值的
打印两条看
console.log(val[0].Id)
console.log(val)
handleSelectionChange这个方法的参数val,指的是原本的数据,一定要注意要深拷贝,不然这里直接修改val,原本的下拉菜单的值就没有了。
参考代码:
<el-table
ref="multipleTable"
:data="gridData"
tooltip-effect="dark"
style="width: 100%"
@selection-change="handleSelectionChange"
>
<el-table-column
type="selection"
style="margin-left: 10px"
/>
</el-table>
handleSelectionChange(val) {
this.$forceUpdate()
const newValue = JSON.parse(JSON.stringify(val))
this.multipleSelection = newValue
for (let i = 0; i < this.multipleSelection.length; i++) {
this.multipleSelection[i].database = this.selectMultipleValue[this.multipleSelection[i].businessLine + this.multipleSelection[i].sourceType]
}
this.$forceUpdate()
},
handleSelectionChange(val) {
this.$forceUpdate()
const newValue = JSON.parse(JSON.stringify(val))
this.ids=newValue
if(this.ids.indexOf(val[0].Id) < 0 ){
this.ids.push(val[0].Id)
} else {
this.ids.splice(this.ids.indexOf(val[0].Id), 1)
}
console.log(idddd,this.Id)
console.log(val)
// console.log('xxx',this.ids)
},