vue安装使用echarts报错“export ‘default‘ (imported as ‘echarts‘) was not found in ‘echarts‘

本文解决了一个在Vue项目中安装ECharts遇到的问题:安装最新版本导致的使用错误,并提供了安装指定版本4.9.0的具体步骤。同时分享了如何在Vue组件中初始化并展示柱状图的实例。

vue安装echarts
按官网方法安装npm install echarts --save
使用报错
"export ‘default’ (imported as ‘echarts’) was not found in ‘echarts’
研究后发现是官网直接安装的版本过高(5.0.0)
需要卸载后安装4.9.0
具体操作如下
1卸载

npm uninstall echarts 

2安装4.9.0版本

npm install echarts@4.9.0

运行成功
附引用实例

<template>
  <div>
   <div id="myChart" :style="{ width: '100%', height: '400px' }"></div>
  </div>
</template>

<script>

export default {
  data() {
    return {
     
    };
  },
  methods: {
    //柱状图
    drawLine() {
      let myChart = this.$echarts.init(document.getElementById("myChart"));
      this.$http
        .post("后台接口地址")
        .then(res => {
          if (res.data.msg == "success") {
            myChart.setOption({
              title: {},
              tooltip: {
                trigger: "axis",
                axisPointer: {
                  type: "shadow"
                }
              },
              grid: {
                left: "3%",
                right: "4%",
                bottom: "3%",
                containLabel: true
              },
              xAxis: {
                type: "category",
                data: '数据',
                axisLabel: {
                  textStyle: {
                    fontSize: 14
                  }
                }
              },
              yAxis: {
                max: 100,
                interval: 20
              },
              series: [
                {
                  name: "综合评分",
                  type: "bar",
                  barWidth: "80",
                  showBackground: true,
                  backgroundStyle: {
                    color: "rgba(110, 193, 244, 0.2)"
                  },
                  itemStyle: {
                    normal: {
                      color: "#29aed7"
                    }
                  },
                  data: '数据'
                }
              ]
            });
          }
        });
    },
  },

  mounted() {

    this.drawLine();

};
</script>


Vue中出现 'export Fragment (imported as Fragment) was not found' 错误,通常是因为尝试从某个模块中导入 `Fragment`,但该模块并未导出 `Fragment`。`Fragment` 一般是在React中使用的,Vue中有类似功能的是 `<template>` 标签。 ### 具体分析及解决办法 #### 1. 检查是否误将React代码用于Vue项目 若在Vue项目里使用了类似React的导入语句,像 `import { Fragment } from 'react'`,就会出现此错误。Vue使用 `<template>` 标签来实现类似 `Fragment` 的功能。 **错误示例**: ```vue // 错误的Vue代码,尝试导入React的Fragment import { Fragment } from 'react'; export default { // ... } ``` **正确做法**: 使用Vue的 `<template>` 标签: ```vue <template> <!-- 这里可以包含多个根元素 --> <div>第一个元素</div> <div>第二个元素</div> </template> <script> export default { // ... } </script> ``` #### 2. 检查自定义模块导入 若从自定义模块导入 `Fragment`,要确保该模块确实导出了 `Fragment`。 **错误示例**: ```javascript // module.js // 没有导出Fragment export function someFunction() { // ... } // main.js import { Fragment } from './module.js'; // 会报错 ``` **正确做法**: 若需要在自定义模块中使用类似 `Fragment` 的功能,可直接使用Vue的 `<template>` 标签,无需导出 `Fragment`。 ### 总结 在Vue中,使用 `<template>` 标签替代React的 `Fragment`,避免在Vue项目里使用React的导入语句,就能解决 'export Fragment (imported as Fragment) was not found' 错误。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值