今天引入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’);
看到这个博主写:https://www.jianshu.com/p/247f66ca8dfe