开发者社区 问答 正文

VUE 中如何导入echarts??报错

我在网上下载的那些echarts.js的文件导入js后各种报错。。。那位大佬分享一下?echrats的js。感谢

展开
收起
爱吃鱼的程序员 2020-06-05 15:34:59 798 分享 版权
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB
                        <p>vue中不需要你单独下echarts.js的文件呢。</p> 
    

    1.npm install echarts --save 
    把模块导入你的工程

    2.

    <template>
      <div :style="{height:'350px',width:'100%'}" ref="myEchart"></div>
    </template>
    import echarts from 'echarts'
      export default {
        data() {
          return {
            options: {
              xAxis: {
                type: 'category',
                data: [1,2]
              },
              yAxis: {
                type: 'value'
              },
              tooltip: {
                trigger: 'axis'
              },
              series: [{
                data: [1,2],
                type: 'line'
              }]
            },
          }
        },
        mounted:{
          echarts.init(this.$refs.myEchart)
        }
      }
    2020-06-05 15:35:14
    赞同 展开评论