1,安装echarts
import echarts from 'echarts'
2,在需要使用图表的组件直接引入
import echarts from 'echarts'
或者全局引入,在main.js中
import echarts from 'echarts'
Vue.prototype.$echarts = echarts
然后在需要使用图表的组件的方法中如下使用
// 基于准备好的dom,初始化echarts实例
let myChart = this.$echarts.init(document.getElementById('myChart'));
myChart.setOption({
title: {
text: 'Echarts'
}
})
下面是一个demo.vue组件的具体实现