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 [email protected] --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; 

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

猜你喜欢

转载自blog.csdn.net/weixin_47406082/article/details/133235725
今日推荐