慕容的工作随笔

慕容的工作随笔

记录学习和工作

【原创】Vue 中使用 echarts

  • 引入 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

评论 (0)

还没有评论,来做第一个吧。

发表评论

提交后需管理员审核通过后显示