Error in mounted hook: "TypeError: Cannot read properties of null (reading 'getAttribute')"
时间: 2023-09-27 18:08:05 浏览: 667
根据引用中的描述,该错误是在运行时遇到的一个错误,报错信息是"TypeError: Cannot read properties of null (reading 'getAttribute')"。据引用所述,可以使用Vue中的ref和$refs来代替document.getElementById()来获取图形容器对象。
因此,解决这个错误的方法是将div的id更改为相应的ref值,并在mounted钩子中使用this.$refs['equan']来引用该图形容器对象。这样就可以正确配置地图并避免报错。请参考以下代码示例:
```javascript
<template>
<div ref="equan" :style="{ width: '100%', height: '220px' }"></div>
</template>
<script>
export default {
mounted() {
var myChart = echarts.init(this.$refs['equan'])
// 其他地图配置操作...
}
}
</script>
```
通过将div的id更改为ref值,并在mounted钩子中使用this.$refs['equan']来引用该图形容器对象,可以解决"Error in mounted hook: TypeError: Cannot read properties of null (reading 'getAttribute')"的问题。<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^v93^chatsearchT3_2"}}] [.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^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文