TypeError: Cannot read property 'getAttribute' of undefined


今天使用echarts + vue 做 圖標,運行時提示vue.runtime.esm.js?2b0e:619 [Vue warn]: Error in mounted hook: "TypeError: Cannot read property 'getAttribute' of undefined"

網上找了些朋友說是,什么要將加載放到mounted的this.$nextTick中,其實不然,是我吧refs 的值寫錯了

現在我們就來開始找錯…

html

<template>
    <div class="echart-box" style="width: 280px;  height:220px" ref="line_only_dom"></div>
</template>

js

  mounted() {
      this.drawLine();
  },
  methods: {
      drawLine() {
          let self = this;
          let line_dom = this.$refs.line_dom;
          this.mychart = this.$echarts.init(line_dom);

	}
}

找到錯誤了吧

只要吧 let line_dom = this.$refs.line_dom; 改為 let line_only_dom = this.$refs.line_only_dom; 問題即可解決


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM