vue.runtime.esm.js:4605 [Vue warn]: Error in mounted hook: "TypeError: Cannot read properties of undefined (reading '0')"
时间: 2023-09-21 13:10:23 浏览: 147
Sawyer-zh#study-note#Vue-js路由报错TypeError-Cannot-read-property-c-
这个错误是由于在mounted钩子函数中对undefined的属性进行读取。根据引用的说明,可以将挂载函数从created中移至mounted中来解决这个问题。在mounted中调用函数之前,确保相关数据已经被正确初始化。具体来说,你可以在return语句后添加`|| {}`来表示如果状态为空对象,则返回一个空对象作为默认值。这样可以避免在读取属性时出现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 ]
阅读全文