vue 使用 echarts
配置:1.npm 安装 echarts (注意安装5.0之下的版本,安装5.0以上的可能会报错)
cnpm install echarts@4.9.0 或者 npm install echarts@4.9.0
2.main.js引入
import echarts from 'echarts'
Vue.prototype.$echarts = echarts
使用:
<template>
<div>
<div class="container">
<div
id="main"
style="width: 600px; height: 400px; margin-top: 40px"
></div>
</div>
</div>
</template>
mounted () {
this.getLoadEcharts()
},
methods: {
// 基于准备好的dom,初始化echarts实例
var myChart = this.$echarts.init(document.getElementById('main'))
// 指定图表的配置项和数据
var option = {
直接引入官网实例即可
}
}
注意:将官网例子中的echarts替换成this.$echarts。因为echarts是基于html,vue全局引入到main中。

浙公网安备 33010602011771号