<el-select
v-model="form.districtCode"
@change="handleChangeArea"
placeholder="请选择所属区域"
style="width: 100%"
>
<el-option
v-for="item in areaList"
:key="item.placecode"
:label="item.name"
:value="item.placecode"
></el-option>
</el-select>
handleChangeArea(placecodes) {
let obj = {};
obj = this.areaList.find((item) => { //this.areaList 是通过接口请求下来的区域列表
return item.placecode === placecodes; //筛选出匹配数据
});
this.form.districtCode = obj.placecode;
this.form.districtName = obj.name;
},
-
find() 方法返回数组中第一个通过测试的元素的值(作为函数提供)
-
find() 方法为数组中的每个元素都调用一次函数执行
-
当数组中的元素在测试条件时返回 true 时, find() 返回符合条件的元素,之后的值不会再调用执行函数。
-
如果没有符合条件的元素返回 undefined
注意: find() 对于空数组,函数是不会执行的;find() 并没有改变数组的原始值。