vue.runtime.esm.js:4605 [Vue warn]: Error in created hook: "TypeError: Cannot read properties of undefined (reading 'id')"
时间: 2023-10-17 10:26:52 浏览: 186
这个报错的原因是在Vue的created钩子函数中,尝试读取一个undefined的属性'id',导致了TypeError。根据引用的信息,这个错误与在使用getters简化数据时忽略了空对象的情况有关。如果state.goodsInfo的初始值为空对象,那么当访问该对象的'id'属性时,会出现undefined的情况,从而导致报错。为了解决这个问题,可以在返回值后面加上或(||)操作符,将初始值设置为一个空对象。这样即使state.goodsInfo为空对象,也不会出现undefined的情况,避免了报错的发生。具体可参考引用中的代码示例。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *3* [报错 | vue.runtime.esm....c320:4560 [Vue warn]: Error in render: “TypeError: Cannot read properties of](https://blog.csdn.net/muziqwyk/article/details/126191223)[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%"]
- *2* [2b0e:619 [Vue warn]: Error in created hook: “TypeError: Cannot read properties of](https://blog.csdn.net/z_langjitianya/article/details/127898258)[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 ]
阅读全文