在Vue脚手架中使用echarts,并解决“TypeError: Cannot read property ‘init‘ of undefined”报错

在Vue中使用echarts,并解决“TypeError: Cannot read property ‘init’ of undefined”报错

1.安装echarts依赖

npm install echarts --save-dev

2.main.js 引入

import echarts from 'echarts'

Vue.prototype.$echarts = echarts

以为这就完了?

控制台很不客气的报错“TypeError: Cannot read property ‘init’ of undefined”

解决办法:main.js中的import echarts from 'echarts’改为import * as echarts from ‘echarts’

3.新建一个Echarts.vue,方法在mounted生命周期中调用

你可能感兴趣的:(在Vue脚手架中使用echarts,并解决“TypeError: Cannot read property ‘init‘ of undefined”报错)