vue使用echarts报错init is undefined...或者this.dom.getContext is not a function

解决办法

  1. init undefined

到package.json中查看,如果ehcarts版本在5.0之上的
使用 import * as echarts from 'echarts'导入

或者用npm uninstall echarts先卸载echarts,安装旧版本
npm i echarts@4 --save

  1. this.dom.getContext is not a function at e.initContext

报错是由于用了jquery来寻找节点,ehcarts不接受jQueryDOM,改用原生方式document.getElementById(“myEcharts”)即可

过程

按网上的文档用 npm i echarts --save 安装了,然后在vue中使用如下代码注册插件

import  echarts from 'echarts'; 
// 并设置对应的属性
Vue.prototype.$echarts = echarts; 

但是调用echarts.init初始化报错,既然init找不到,我首先想的就是输出一下echarts这个东西,看看他的结构

console.log(this.$echarts)

结果为undefined

正确安装了,但是导入没有东西,这种情况肯定是导入姿势不正确

import导入的前提是某个文件进行了导出,比如export default{}

直接查看node_modules中的echarts目录下的index.js,发现里面全是use函数在使用各个模块,并没有导出,使用import * as echarts from 'echarts'; 将里面的东西集成到一坨

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值