Echarts出现 “init of undefined“或“echarts is not defined“ 的解决方案

最近用Echarts做毕业设计首页图表出现了“init of undefined“ 和 "echarts is not defined" 


在网上百度了解决方案,然后又看了一下官方文档,才发现 Echarts5.0或6.0的引入方式和Echarts4的引入方式不一样了。

我引入时用的6.0版本

解决方式如下: 

方案1、将Echarts版本降到4.0


// 首先先写在echarts的最新版本
npm uninstall echarts --save

// 可以安装4.8.0版本(@后面是指定想安装的版本号)
npm install echarts@4.8.0 --save

// 安装完成之后就可以正常使用了

然后在main.js重新全局引入

// 引入echarts
import echarts from 'echarts'
Vue.prototype.$echarts = echarts

方案2:使用Echarts5/6的方式引入

// 在 main.js 中引入echarts
import * as echarts from 'echarts';
Vue.prototype.$echarts = echarts; 

// 这样问题也完美解决了

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

星浩前进中

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值