Uncaught TypeError: Cannot read properties of undefined (reading 'BASEINFO')
时间: 2023-08-18 10:15:15 浏览: 114
根据提供的引用内容,报错"Uncaught TypeError: Cannot read properties of undefined (reading 'BASEINFO')"是因为在访问对象的属性时,对象为undefined。具体来说,当访问store.user.state.userInfo.data.id时,userInfo对象为空,因此无法读取id属性,导致报错。\[2\]
解决这个问题的方法是在访问属性之前,先确保对象存在并且不为undefined。可以使用条件语句或者可选链操作符(optional chaining)来进行判断,以避免访问不存在的属性而导致报错。例如,可以使用以下代码来访问userInfo对象的id属性:
```javascript
const id = store.user.state.userInfo?.data?.id;
```
这样,如果userInfo对象或者data对象不存在,id将会被赋值为undefined,而不会导致报错。\[2\]
#### 引用[.reference_title]
- *1* [vue Uncaught (in promise) TypeError: Cannot read properties of undefined (reading ‘comcode‘)](https://blog.csdn.net/jungeCSND/article/details/130059965)[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^v91^control,239^v3^insert_chatgpt"}} ] [.reference_item]
- *2* *3* [解决Uncaught (in promise) TypeError: Cannot read properties of undefined (reading ‘id‘)报错](https://blog.csdn.net/m0_57524265/article/details/131441971)[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^v91^control,239^v3^insert_chatgpt"}} ] [.reference_item]
[ .reference_list ]
阅读全文