echarts报错'getAttribute' of undefined

$nextTicksetTimeoutdestroyed()这些能用的都用了,还是不管用,依旧报错

echarts报错'getAttribute' of undefined
echarts报错'getAttribute' of undefined
之前是这样子的。但是他刷新会有问题就改了外层样式,使用百分比,再把echarts放进去就开始报错了。
echarts报错'getAttribute' of undefined

html

<div class="main-cont">

<a-row :gutter="16" class="cont-tone">

<a-col :span="18">

<div class="echarts-box">

<div

:style="{

width: '100%',

height: '324px',

backgroundColor: '#f0fff9',

}"

ref="myChart2"

></div>

</div>

</a-col>

<a-col :span="6">

</a-col>

</a-row>

js

  updated() {

this.setChart4();

this.setChart1(this.echartsData, this.cName);

this.setChart2();

this.setChart3();

},

mounted() {

this.$nextTick(() => {

console.log(this.$refs.myChart2); // 可以获取到

this.setChart4();

this.setChart1(this.echartsData, this.cName);

this.setChart2();

this.setChart3();

});

// setTimeout(()=>{

// this.setChart4();

// this.setChart1(this.echartsData, this.cName);

// this.setChart2();

// this.setChart3();

// },50)

},

destroyed () {

window.removeEventListener('resize', this.setChart2, 20)

},

methods: {

// 柱形

setChart2() {

var myChart2 = this.$echarts.init(this.$refs.myChart2);

window.addEventListener("resize", function() {

myChart2.resize();

});

myChart2.setOption({

// options

});

},

}

回答

这个错误就是没找到dom 也就是dom还没加载就执行了init

this.$refs.myChart2 这个打印出来了 需要看下 下面的方法
this.setChart4();里面有没有顺序写错的地方

以上是 echarts报错'getAttribute' of undefined 的全部内容, 来源链接: utcz.com/a/65642.html

回到顶部