今天使用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);
}
}
找到錯誤了吧
