当使用element ui 的select选择器选择一个选项时,使用@change事件时只能得到一个Id,想要得到Id对应的对象用到filter进行过滤取到才可以。
以下代码:
<el-select v-model="dataForm.varietyIds" multiple placeholder="请选择试验品种" style="width:300px" @change="changeVarietyIds">
<el-option
v-for="item in varietyOptions"
:key="item.id"
:label="item.name"
:value="item.id"
/>
</el-select>
changeVarietyIds(val) {
this.$forceUpdate()
this.newList = []
val.map(v => {
const list = this.varietyOptions.filter(item => {
return item.id === v
})
const obj = list[0]
this.newList.push(obj)
})
},