Invalid prop: type check failed for prop "goods". Expected Object, got Number with value 20.
时间: 2023-10-19 20:31:57 浏览: 161
这个错误是由于在Vue项目中,父组件向子组件传递的属性类型不一致导致的。具体来说,在父组件中将一个数字20传递给了子组件的属性"goods",但是子组件的属性类型却定义为了对象,因此就会出现类型检查失败的错误。为了解决这个问题,需要修改子组件的属性定义,将属性类型改为数字类型。可以像下面这样修改子组件的代码:
```
export default {
props: {
goods: {
type: Number,
default: 0
}
}
}
```
这样修改之后,就能正确地传递属性值并通过类型检查了。注意在这个例子中,我们将属性的类型改为了数字类型,同时设置了默认值为0。这样可以保证属性在未传递值时的默认类型为数字,并且在接收到父组件传递的数字属性时不会再出现类型检查失败的错误提示。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *2* [Invalid prop:type check failed for prop.Expected String with value“[object Object]”got Object](https://blog.csdn.net/qq_45796592/article/details/131870831)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
- *3* [Vue报错:Invalid prop: type check failed for prop “roleList“. Expected Object, got Array 解决方法](https://blog.csdn.net/qq_41782425/article/details/132202943)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文