vue中使用 echart 报错undefined

学弟踩坑问我的,个人觉得有必要写一下。

可能会出现的错误

  • Cannot read property 'init' of undefined"

  • 打印echarts对象为undefined

排错方式

  • 查看引入方式是否正确
  • 查看 package.json 文件下是否有echarts的包,并确认 echarts包的版本
  • 如果安装包的版本大于 4.9,使用 
    import * as echarts from 'echarts'

    引入

  • 或者 npm install [email protected] ,安装旧版本,(不推荐)

vue 项目中个人推荐使用基于 Vue2.x 的 Echarts 组件 v-charts 的。

猜你喜欢

转载自blog.csdn.net/qq_42044542/article/details/114605564