vue项目中使用echarts
1. 安装
npm install echarts -S
2. 引入
- 全局引入
//main.js文件中
import * as echarts from 'echarts'
Vue.prototype.$echarts = echarts
- 单个文件引入
//.vue文件
3. 使用
- 单个文件引入
注意1:要在mounted生命周期函数中实例化echarts对象。确保页面上的元素已经渲染完毕
如果是全局引入,使用时,要加this.$
var myChart = this.$echarts.init(document.getElementById('main'))
注意2:
导入echarts运行依赖时,不能这样import echarts from 'echarts'导入,否则会出现Error in mounted hook: "TypeError: echarts__WEBPACK_IMPORTED_MODULE_0__.default is undefined"的错误