vue elementui中,el-select多选下拉列表中,获取:value和:label的值
程序员文章站
2022-05-31 15:37:15
...
<el-form-item label="标题:">
<el-select
placeholder="请选择"
multiple
style="width:100%"
v-model="queryParams.craftId"
size="mini"
@change="processingTechnic">
<el-option
v-for="item in processingTechnicOptions"
:key="item.id"
:label="item.name"
:value="item.id"
/>
</el-select>
</el-form-item>
data() {
return {
processingTechnicOptions:[],
craftName:'',
craftId:[],
craftNames:[],
}
},
methods:{
// 方法1
processingTechnic(val){
var names = "";
for(let i=0;i<=val.length-1;i++){
this.processingTechnicOptions.find((item)=>{
if(item.id == val[i]){
names += item.name + ",";
}
});
}
this.craftName = names;
},
// 方法2
processingTechnic(val){
this.craftId = [];
this.craftNames= [];
for(let i=0;i<=val.length-1;i++){
this.processingTechnicOptions.find((item)=>{
if(item.id == val[i]){
this.craftId.push(item.id);
this.craftNames.push(item.name);
}
});
}
console.log(this.craftId)
console.log(this.craftNames)
},
},