在开发过程中使用Element UI中Select下拉框时可能会遇到绑定对象的情况,总结如下:
<el-select v-model="productionClassId" value-key="id" @change="deptChangeVal" style="width:200px" placeholder="请选择"><el-optionv-for="item in optionsDept":key="item.id":label="item.title":value="item"></el-option></el-select>
value-key:作为 value 唯一标识的键名,绑定值为对象类型时必填
data () {return {productionClassId: '', // select上绑定的值}}methods:{// 选中值时获取对象deptChangeVal(val){console.log(val,'选中对象');},// 编辑回显时editBtn(row){this.dialogFormVisible = true;this.productionClassId = row.productionClassName;},}
测试有效!!!