TypeError: Cannot read properties of undefined (reading '1')报错但是可以获取到值
时间: 2023-10-17 10:31:12 浏览: 250
解决jquery插件:TypeError:$.browser is undefined报错的方法
根据引用的描述,当访问一个对象的属性时,如果该属性不存在,结果会是undefined。但如果接着访问该属性的属性,则会出现TypeError报错。因此,对于报错"TypeError: Cannot read properties of undefined (reading '1')",虽然报错了但可以获取到值的情况,可能是因为在访问属性时使用了安全访问运算符(?.)。安全访问运算符可以在访问对象属性时,如果属性不存在,则会立即返回undefined,而不会出现TypeError报错。例如,使用store.state.user?.data?.id来访问对象中的属性,如果其中任何一个属性不存在,都会返回undefined而不会报错。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *3* [TypeError: Cannot read properties of undefined (reading ‘NAME‘)报错解决](https://blog.csdn.net/guapilixianghe/article/details/129284383)[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_1"}}] [.reference_item style="max-width: 50%"]
- *2* [解决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^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文