el-select中当显示的label与使用的value值不一样的时候,如何获取所选中的对象。
html代码
<el-select v-model="device.outDevice" :disabled="disabled" placeholder="请选择内容" size="mini" style="width:20%;" @change="handleSelect" > <el-option v-for="item in outDevice" :key="item.id" :label="item.deviceName" :value="item.deviceId" /> </el-select>
js代码
<script> export default { data() { return { device: { outDevice: '' }, outDevice: [ {deviceId:'001',deviceName:'001'}, {deviceId:'002',deviceName:'002'}, {deviceId:'003',deviceName:'003'} ], outData: {}, } }, methods: { handleSelect(val) { var obj = this.outDevice var hostValue = {} obj.forEach((item, index) => { const deviceId = item.deviceId if (!hostValue[deviceId]) { hostValue[deviceId] = { item } } }) this.outData = hostValue[val].item } } } </script>