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

Categories

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

echarts报错'getAttribute' of undefined

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

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

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
      });
    },
  }
  
  

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

1 Reply

0 votes
by (71.8m points)

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

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...