Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
332 views
in Technique[技术] by (71.8m points)

vue结合echarts报错问题

1、在页面中写的echarts容器:

<div id="charts-one" class="echart" ref="chartsOne"></div>

在方法里面获取用了document.getElementById("charts-one") 以及this.$refs.chartsOne然后再init的时候会报错,前一种方式报TypeError: Cannot read property 'getAttribute' of null后面那种报TypeError: Cannot read property 'getAttribute' of undefined
2、自己尝试解决的办法:
在mounted中用之后的办法 还是不可以,

1、this.$nextTick(()=>{方法)}
2、setTimeout(()=>{
      this.dataTotal();
    },50)

3、虽然报错但是页面数据还是渲染成功,希望大神解惑,谢谢


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

你这个问题描述很模糊你应该先打印下 this.$refs['chartsOne'] 查看下有没有获取到这个节点 建议相关初始化代码以入 mounted 试试


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...