js报错 Cannot read property 'getAttribute' of null
程序员文章站
2023-01-22 15:30:00
页面echarts.js报错:Uncaught TypeError: Cannot read property 'getAttribute' of null ......
页面echarts.js报错:uncaught typeerror: cannot read property 'getattribute' of null
根据报错信息查找原因发现是因为 实例化echarts的元素不存在,查看官方文档发现:
// 基于准备好的dom,初始化echarts实例 var mychart = echarts.init(document.getelementbyid('main'));
基于准备好的dom,初始化echarts实例,也就是只有 页面存在的html元素 才可以去初始化。
如果不知道页面是否存在此html元素,那么在 实例化echarts前 去打印一下看看
console.log(document.getelementbyid('main'))
推荐阅读
-
Vue报错:Uncaught TypeError: Cannot assign to read only property’exports‘ of object
-
npm ERR! Cannot read property 'path' of null
-
js报错 Cannot read property 'getAttribute' of null
-
webpack报错Cannot read property 'presetToOptions' of undefined
-
JavaScript Uncaught TypeError: Cannot read property 'value' of null
-
Vue报错:Uncaught TypeError: Cannot assign to read only property’exports‘ of object’#
-
el-tooltip组件中content使用Vue-i18n报错TypeError: Cannot read property ‘$t‘ of null
-
Extjs4 tabPanel关闭后打开 cannot read property addcls of null
-
Vue报错:Uncaught TypeError: Cannot assign to read only property’exports‘ of object
-
Vue引入echarts报错Error in mounted hook: “TypeError: Cannot read property ‘getAttribute‘ of null“