[Vue warn]: Invalid prop: type check failed for prop “value“. Expected String, Number, got Null.

错误场景:

vue 渲染下拉框的时候报这个错,value传了个空

报错内容:

[Vue warn]: Invalid prop: type check failed for prop "value". Expected String, Number, got Null.

代码:

 <Select v-model="form.merchant" @on-change="changeWholeLink" clearable> 
    <Option v-for="item inMerchantList" :key="item.id" :value="item.nameCh">
    	{
    
    {
    
     item.nameCh }}
    </Option>
</Select>

解决:

提示很明显了,value属性值为空。那我们就找页面哪里用了value属性,可以看到下拉框的Option里面用到了value,取值 item.nameCh,这就说明,当页面渲染的时候item.nameCh有一项为空,即inMerchantList数组中有一项nameCh属性返回为null或者undefined等。所以需要把空数据过滤掉。

在获取 的时候过滤

 this.inMerchantList= this.inMerchantList.filter((item) => {
    
    
          return item.nameCh!=undefined
})

猜你喜欢

转载自blog.csdn.net/weixin_39818813/article/details/118724566