引用echarts報錯Cannot read property ‘init‘ of underfined
阿新 • • 發佈:2021-01-25
檢查一下 echarts 的版本
"echarts": "^5.0.0", // 替換為4.8.0
正確下載和使用
1.下載 ^4.8.0
版本的echarts
npm install --save [email protected]
2.在main.js
中引入 echarts(全域性引入)
import echarts from 'echarts'
Vue.prototype.$echarts = echarts
3.在.vue頁面中使用
echarts
<div ref="myChart" id="myChart" style="width: 100%; height: 500px;"></div>
let myChart = echarts.init(this.$refs.myChart)
// 或者
let myChart = this.$echarts.init(document.getElementById("myChart"));