Ant Design Vue Select 报错
vue.runtime.esm.js?2b0e:619 [Vue warn]: Error in data(): "TypeError: Cannot read properties of null (reading 'key')"
vue.runtime.esm.js?2b0e:1888 TypeError: Cannot read properties of null (reading 'key')
[Vue warn]: Error in render: "TypeError: Cannot read properties of undefined (reading 'length')"
代码如下
<a-col :span="4">
<a-form-model-item label="证件类型">
<a-select v-model="registerParam.idCardType" label-in-value placeholder="请选择证件类型" option-filter-prop="children" @change="idCardTypeChange">
<a-select-option value="0"> 居民身份证 </a-select-option>
<a-select-option value="1"> 居民户口本 </a-select-option>
<a-select-option value="2"> 护照 </a-select-option>
<a-select-option value="3"> 军官证 </a-select-option>
</a-select>
</a-form-model-item>
</a-col>
const idCardType=null;
原因分析:
如果你用了 label-in-value ,idCardType就一定要设置 key value, 例如{ key: ‘0’, label: ‘居民身份证’ },如果你没有使用 label-in-value,反而设置了也会报错
Avoid using non-primitive value as key, use string/number value instead.
解决方案:
提示:使用了 label-in-value,一定要对应{ key: ‘0’, label: ‘’ },这种格式!