在vue中使用echarts报错Cannot read property getAttribute of null
报错信息如下:

报错代码:
mounted() {
// ...
this.drwaCharts() // drawCharts方法为自己定义的包含渲染 echarts 图表的方法
// ...
}
之前一直用 echarts 没有出现过这个问题,所以当这个问题出现时我就开始了各种查,试了几种方法依旧报错,比如:
1、在mounted() {},使用 $nextTick:(依旧报错)
this.$nextTick(() => {
this.drawCharts()
});
2、使用 setTimeout 包裹: (依旧报错)
setTimeout(() => {
this.drawCharts()
}, 1000);
3、正确的方法
因为我在包裹echarts标签的最外层加了v-if,所以导致了报错,只要把v-if改成v-show就可以了~
以上解决方法来自 https://www.cnblogs.com/carriezhao/p/11434998.html
原因分析
报错地点:
在放 echarts 图表的 div 使用了 v-if 指令,在绑定的值为 false 时会报此错,而值为 true 时候不会报错。
原因分析:
我们都知道,在切换显示与隐藏很少的情况下,使用 v-if 会性能更好,所以我根据实际情况首先选择了 v-if 指令。但是因为隐藏的时候, v-if 会使整个 dom 节点不渲染,而 v-show 只是给 dom 节点加了 display: none;属性,节点依然存在 。所以在这种特殊的情况下,由于 v-if 值为 false 时候mounted 中画图的方法依然会执行,在获取 dom 节点时获取不到,所以就会导致报错。
在vue中使用echarts报错Cannot read property getAttribute of null的更多相关文章
- 记录下vue 中引用echarts 出现 "TypeError: Cannot read property 'getAttribute' of undefined"问题
今天做项目,用echarts展示数据 ,自己测试 先测试 了下.写的代码html: <div ref="myChart" style="height:300px;w ...
- echarts js报错 Cannot read property 'getAttribute' of null
本文将为您描述如何解决 eharts.js报错 Uncaught TypeError: Cannot read property 'getAttribute' of null 的问题 根据报错信息查找 ...
- vue中使用JSX报错,如何解决
Support for the experimental syntax 'jsx' isn't currently enabled (32:12): 30 | }, 31 | render() { & ...
- js执行函数报错Cannot set property 'value' of null怎么解决?
js执行函数报错Cannot set property 'value' of null 的解决方案: 原因:dom还没有完全加载 第一步:所以js建议放在body下面执行, 第二步:window.on ...
- hexo 报错 Cannot read property 'replace' of null
详细错误信息: FATAL Cannot read property 'replace' of null TypeError: Cannot read property 'replace' of nu ...
- vue中npm install 报错之一
报错原因: 这是因为文件phantomjs-2.1.1-windows.zip过大,网络不好,容易下载失败 PhantomJS not found on PATH 解决方案一: 选择用cnpm ins ...
- Vue tools开发工具报错Cannot read property '__VUE_DEVTOOLS_UID__' of undefined
使用 vue tools 开发工具,不显示调试面板中的组件,点击控制台报错: Cannot read property 'VUE_DEVTOOLS_UID' of undefined 在 main.j ...
- echarts报错Cannot read property 'features' of undefined
引入地图的时候 echarts2报错: Uncaught Error: [MODULE_MISS]"echarts/src/util/mapData/params" is not ...
- 报错”Cannot read property 'addEventListener' of null“
1.报错:Cannot read property 'addEventListener' of null 2.解决方案: 把代码放到window.onload=function(){...}里面,因为 ...
随机推荐
- Nginx配置中文参数说明
#定义Nginx运行的用户和用户组 user www www; # #nginx进程数,建议设置为等于CPU总核心数. worker_processes 8; # #全局错误日志定义类型,[ debu ...
- 渲染导航菜单的同时给每个菜单绑定不同的router跳转
这个问题一开始的时候,我总想着router跳转只有两种方式 一种@click,一种router-link 然后我想着@click,绑定一个事件,事件下面无法确定我当前是哪个菜单,解决不了. 然后< ...
- PHP curl_share_init函数
(PHP 5 >= 5.5.0) curl_share_init — 初始化一个 cURL 共享句柄 说明 resource curl_share_init ( void ) 允许两个 cURL ...
- PHP fputcsv() 函数
定义和用法 fputcsv() 函数将行格式化为 CSV 并写入一个打开的文件中. 该函数返回写入字符串的长度.如果失败,则返回 FALSE. 语法 fputcsv(file,fields,seper ...
- PHP decoct() 函数
实例 把十进制转换为八进制: <?phpecho decoct("30") . "<br>";echo decoct("10&quo ...
- 5.20 省选模拟赛 求和 组合数的性质 EGF CRT
LINK:求和 绝妙的一道题目.没做绝对亏了. 对于第一个subtask 考虑直接递推出组合数. 对于第二个subtask 考虑EGF 设两个EGF 都只含偶数项指标且系数为1的那种 一个到n一个到m ...
- SpringBoot 发送邮件和附件
作者:yizhiwaz 链接:www.jianshu.com/p/5eb000544dd7 源码:https://github.com/yizhiwazi/springboot-socks 其他文章: ...
- Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependen
Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependen ...
- Idea Live Temlpates 自定义代码
Idea Live Temlpates 自定义代码 目的 - 加快常用代码的书写 使用## 打开Settings 快捷键Ctrl+Alt+S 选中Live Templates 选中temlpates ...
- JS 移动端轮播图案例
body { margin:; } .hearder { width: 100%; height: 150px; position: relative; } ul { list-style: none ...