步骤:
举例:select数据格式为:
options: [
{
value: '1',
label: '黄金糕'
},
{
value: '2',
label: '双皮奶'
}
]
一:label的获取
1.定义事件
<el-select v-model="form.receivePaymentCustomerId" placeholder="请选择" size="small" filterable @change="customerChange">
<el-option v-for="(item, index) in customerOptions" :key="index" :label="item.label" :value="item.value" style="width:182px" />
</el-select>
2.事件中做循环处理
customerChange(id) {
const thisLabel = this.customerOptions.find(item => item.value === id).label
console.log(`label----->`, thisLabel) //label-----> 国风
},
如图:
二:value的获取
value的获取很简单:
console.log(`value----->`,this.form.receivePaymentCustomerId) //value----->505177042653202
由此可以得出:el-select筛选框展示label,取值value