1,先在package.json添加依赖
"dependencies": {
"echarts": "^4.2.1",
"vue": "^3.0.0"
},
2,在main.js
import echarts from ‘echarts’
报错 "export ‘default’ (imported as ‘echarts’) was not found in ‘echarts’ 改成下面的引用。
import Vue from 'vue'
const echarts = require('echarts');
//把echarts挂载到vue的原型链上,这样在任何组件里面,都可以通过this.$echarts 调用
Vue.prototype.$echarts = echarts
3,在展示的页面写代码
<div id="myChart" :style ="{width:'300px',height:'300px',margin:'op auto'}"></div>
methods: {
loadData() {
let myChart = this.$echarts.init(document.getElementById('myChart'));
myChart.setOption({
...........
})
}