一、安装
cnpm install echarts --save
二、引用
局部引用
import echarts from 'echarts'
全局引用
在main.js中
import echarts from 'echarts'
Vue.prototype.$echarts = echarts
三、使用
html代码
<div id="myChart" :style="{width: 'auto', height: '400px'}"></div>
js代码
methods: {
//this.report 是从后台获取的数据
drawline() {
let myChart = this.$echarts.init(document.getElementById("myChart"));
myChart.setOption(this.report);
}
},
// handler在watch侦听开始之后最初绑定的时候就执行
watch: {
report:{
handler(){
this.drawline()
}
}
},