Echarts报错 Cannot read property ‘init’ of undefined

最近vue中使用Echart时发现不兼容的地方,出现奇怪的报错
Error in mounted hook: “TypeError: Cannot read property ‘init’ of undefined”

造成问题的原因有两个,一个是初始化的时候没有获取到DOM元素,另一个是引入Echart这个库的方式错误,解决如下:

1.使用ref获取DOM元素:

this.Chart = echarts.init(this.$refs.chartDom)

2.改用require的方式引入库:

let echarts = require('echarts');

你可能感兴趣的:(Echarts报错 Cannot read property ‘init’ of undefined)