Vue 中使用 'el-select' 组件时出现的 'Cannot use 'in' operator to search for 'brandId' in null' 错误解决方法
这段代码中的问题在于 'v-model' 绑定的变量名为'this.brandId',在 Vue 中不应该使用'this' 关键字来引用 data 中的属性,而应该直接使用属性名。另外,初次渲染时 brandId 可能为 null,所以需要在 data 中初始化为一个默认值。
正确的代码应该为:
<el-form-item label='品牌' prop='brandId'>
<el-select v-model='brandId' placeholder='品牌'>
<el-option v-for='item in brandList' :key='item.brandId' :label='item.name' :value='item.brandId'></el-option>
</el-select>
</el-form-item>
并且在 data 中初始化 brandId:
data() {
return {
brandId: null,
brandList: [],
// ...
}
}
原文地址: https://www.cveoy.top/t/topic/m1aH 著作权归作者所有。请勿转载和采集!