Error in mounted hook: "TypeError: Cannot read properties of undefined (reading 'getAttribute')"
时间: 2023-09-26 07:10:52 浏览: 93
这个错误是因为在mounted钩子函数中,尝试读取一个未定义的属性'getAttribute'引起的。根据引用的描述,这个错误可能是由于在配置Echarts地图时,使用了错误的元素ID。你可以使用Vue中的ref和$refs来代替document.getElementById()来获取图形容器对象,如引用所示。通过给div元素添加ref属性,然后在mounted钩子函数中使用this.$refs['equan']来获取该图形容器对象。这样可以避免因为ID值错误而导致的属性读取错误。请确保div元素的ref属性与mounted钩子函数中的引用名称一致。另外,根据引用的描述,也要确保div元素的id属性与调用的地图配置中的ID值保持一致。这样就能够正确配置地图并避免TypeError错误的发生。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *3* [Vue 报错Error in mounted hook: “TypeError: Cannot read properties of null (reading ‘getAttribute...](https://blog.csdn.net/weixin_60364883/article/details/121759164)[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^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
- *2* [: Error in mount hook: “TypeError: Cannot read properties of null (reading ‘getAttribute‘)](https://blog.csdn.net/weixin_49686572/article/details/126638771)[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^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文