Cannot read property 'init' of undefined"

来源:5-11 累计订单量组件开发

Jerry卢

2020-12-11

折线图没有显示出来。
Error in mounted hook: “TypeError: Cannot read property ‘init’ of undefined”

<template>
          <div id="total-orders-chart" :style="{width : '100%', height : '100%'}"></div>
</template>
mounted() {
      const chartDom = document.getElementById('total-orders-chart');
      const chart = this.$echarts.init(chartDom)
      chart.setOption({
          xAxis: {},
          yAxis: {},
          series: [{
              type: 'line',
              data: [620, 432, 220, 534, 790, 430, 220, 320, 532, 320, 834, 690, 530, 220, 620]
          }]
      })
  }
写回答

3回答

Jerry卢

提问者

2020-12-11

解决了,版本问题,别使用5.0,我使用4.8版本就可以了

2
0

素颜19

2021-02-25

5.0引入方式 import * as echarts from 'echarts';

1
0

Yitea

2021-02-17

同样的问题,在package.json->dependencies中echarts的版本改为4.8.0就好了

"dependencies": {
  "core-js": "^3.6.5",
  "echarts": "^4.8.0",
  "element-ui": "^2.4.5",
  "vue": "^2.6.11",
  "vue-router": "^3.2.0"
}


0
0

数据可视化入门到精通-打造前端差异化竞争力

同级别前端,掌握数据可视化薪资更高

1520 学习 · 1043 问题

查看课程