前端开发那些事儿

在Vue脚手架中使用echarts,并解决“TypeError:

2021-07-20  本文已影响0人  SY

在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生命周期中调用

上一篇 下一篇

猜你喜欢

热点阅读