本博文解决的问题
- 引用echarts时,图表不显示,且控制台报错‘Cannot read property ‘init’ of undefined’
- echarts在vue3中的使用
composition-api 移步
echarts安装
npm install echarts --save
js部分
echarts 5.0版本接口更新后,echarts 引入方式
由import echarts from ‘echarts’ 变更为 import * as echarts from ‘echarts’,
如不按此引用,图表不会显示,且控制台会报 ‘Cannot read property ‘init’ of undefined’
此处参考原博文地址 https://blog.csdn.net/qq_41636947/article/details/110879791
import * as echarts from 'echarts';
1.定义一个函数echartInit(),用于初始化图表,并指定图表的配置项和数据
setup(){
const echartInit = () =>{
var myChart = echarts.init(document.getElementById('main'));
// 指定图表的配置项和数据
var option = {
title: {
text: 'ECharts 入门示例'
},
tooltip: {
},
legend: {
data:[&