在運(yùn)行Vue項(xiàng)目時(shí)出現(xiàn)了控制臺(tái)報(bào)錯(cuò):
[Vue warn]: Error in mounted hook: "TypeError: Cannot read property 'getAttribute' of null"
然后echarts圖沒(méi)有顯示。

報(bào)錯(cuò)圖示
原因:Echarts的圖形容器還未生成就對(duì)其進(jìn)行了初始化所造成的。
解決辦法:
利用Vue中的ref和$refs 來(lái)代替document.getElementById()獲取該圖形容器對(duì)象。
報(bào)錯(cuò)代碼如下:
//html
<template>
<div id="main-eChartsAllProducts"></div>
</template>
//js
this.charts = this.$echarts.init(document.getElementById(id));
改完后代碼:
//html
<template>
<div id="main-eChartsAllProducts" ref="chart"></div>
</template>
//js
this.charts = this.$echarts.init(this.$refs.chart);