1. 程式人生 > 其它 >引用echarts報錯Cannot read property ‘init‘ of underfined

引用echarts報錯Cannot read property ‘init‘ of underfined

技術標籤:VUEechartsinit4.8.0

在這裡插入圖片描述

檢查一下 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"));