<el-form-item label="维护人员:">
<el-select
v-model="mountData.userName"
filterable
placeholder="请选择人员"
@change="handleGetUserName"
>
<el-option
v-for="item in getSelectUserlist"
:value="item"
:key="item.id"
:label="item.name"
></el-option>
</el-select>
</el-form-item>
<script>
export default {
data(){
getSelectUserlist[
{id:1,name:"wangzi"}
{id:2,name:"wangzi2"}
],
mountData:{ // 定义的数据,前后交互
userName:“”,
userId :‘“”
}
},
methods:{
handleGetUserName(val) {
console.log("handleGetUserName", val);
this.mountData.userName = val.name;
this.mountData.userId = val.id;
},
}
}
</script>
重点是把每一个选项的值绑上个对象。这个对象会传给change(val)函数,通过这个函数给表单赋值