-
引入
import * as echarts from 'echarts';
-
页面
<div id="main" style="width: 600px; height: 400px"></div>
-
js
mounted () { this.echartsInit(); }, methods: { echartsInit () { echarts.init(document.getElementById('main')).setOption({ title: { text: 'ECharts 入门示例' }, tooltip: {}, legend: { data: ['销量'] }, xAxis: { data: ['衬衫', '羊毛衫', '雪纺衫', '裤子', '高跟鞋', '袜子'] }, yAxis: {}, series: [ { name: '销量', type: 'bar', data: [5, 20, 36, 10, 10, 20] } ] }); } }
注意
调用 echarts 如果控制台出现报错 Cannot read properties of undefined (reading ‘init‘)
是因为引入错误导致。
import echarts from 'echarts'; // 错误的引入
import * as echarts from 'echarts';//echarts 官网引入方法
参考链接:https://blog.csdn.net/Jwybwy/article/details/124302745
更多精彩内容:各种AI课程、技能课程、黑科技软件、网站小程序源码、副业小项目、PPT模板等精品素材、电商课程、推广引流课程等,尽在 天边资源网 。