下拉框为多选时,绑定的值为数组状态,所以点击编辑赋值时,需要处理为数组
但我遇到的问题是,可以赋值,但不是想要的结果,我想要显示label,但显示的是value
不想得到的效果:
在这里插入图片描述
想要的是:
在这里插入图片描述
在赋值后面加“map(Number)”就可以对号入座了
<el-form-item label="通知对象:" prop="userIds">
<el-select v-model="form.userIds" filterable multiple placeholder="请选择" style="width:100%">
<el-option
v-for="(item,i) in userData"
:key="i"
:label="item.userName"
:value="item.userId">
</el-option>
</el-select>
</el-form-item>
async handleUpdate(row) {
this.visibleModal = true
this.title = "修改"
this.form.id = row.id;
const res = await getEventInfo(row.id)
if(res.code == 200){
for(let key in this.form){
this.form[key] = res.data[key]
}
if(res.data.userId){
this.form.userIds = res.data.userId.split(',').map(Number)//主要赋值代码
}
}
},