element下拉多选项回显
需求:在新增页面下拉选项多选之后,在编辑页面要回显出来(新增页跟编辑页共用一个页面)
<el-form-item label="锁类型" prop="selectListvalue">
<el-select
v-model="selectListvalue"
multiple
placeholder="请选择锁类型">
<el-option
v-for="item in locktypelist"
:key="item.value"
:label="item.label"
:value="item.value">
</el-option>
</el-select>
</el-form-item>
data() {
return {
selectListvalue:[],
//连点
noClick:true,
isAdd: true, //表明新增还是编辑
addOrUpdateVisible: false,
locktypelist:[],
dataForm: {
Locktype:[],
},
dataRules: {},
};
},
showAndInit(row) {
//编辑
if (row) {
this.addOrUpdateVisible = true;
this.isAdd = false;
this.dataForm = JSON.parse(JSON.stringify(row));
this.selectListvalue = this.dataForm.lockType.split(',') || [];//此处下拉多选回显赋值
//新增
} else {
this.addOrUpdateVisible = true;
this.isAdd = true;
this.dataForm = {
lockType: []
};
}
},