从版本4.1.0更新echarts版本的升级后Vuejs错误 - 4.2.0-rc.2

问题描述 投票:0回答:1

我创造了使用Vue的-CLI在vuejs项目。我必须从更新版本4.1.0 echarts的版本到4.2.0版,rc.2。更新后,它会出现如下错误:

  1. 在终端它显示错误:

“出口‘默认’(导入为‘echarts’)在‘echarts / lib目录/ echarts’未找到

  1. 并在访问条形图页面,它显示在控制台错误:

类型错误:无法分配给只读属性对象“#”的“出口”

更新echarts包之前,这里是我的代码

vue.config.js文件

const path = require('path');
const webpack = require('webpack');

module.exports = {
  baseUrl: process.env.NODE_ENV == 'production' ? '/' :  '/',
  transpileDependencies: [
    /\bvue-echarts\b/,
    /\bresize-detector\b/
  ],
  configureWebpack: {
    plugins: [
      //jquery plugin
      new webpack.ProvidePlugin({
        $: 'jquery',
        jquery: 'jquery',
        'window.jQuery': 'jquery',
        jQuery: 'jquery'
      })
    ]
  }
}

更新echarts版本后,我已经取代了与这些行代码的几行:

transpileDependencies: [
  /\/node_modules\/vue-echarts\//,
  /\/node_modules\/resize-detector\//
],

在更新这些行,我已经解决了第一个错误。但在下面的错误echarts页面出现在控制台:

误差在安装钩:“错误:组件series.bar不存在第一加载它。”。

这里是我的条形图文件:

    <template>
      <ECharts :options="bar" style="width:100%; height:300px"></ECharts>
    </template>

    <script>
      import ECharts from "vue-echarts/components/ECharts.vue";
      import "echarts/lib/chart/bar";
      import "echarts/lib/component/title";
      import { ChartConfig } from "Constants/chart-config";

      export default {
        components: {
          ECharts
        },
        data() {
          return {
            bar: {
             tooltip: {
             trigger: "axis"
            },
            color: [ChartConfig.color.danger],
            legend: {
             data: ["Series A"]
           },
           xAxis: {
             type: "category",
             boundaryGap: true,
             data: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul"]
           },
           yAxis: {
             type: "value",
             axisLabel: {
             formatter: "{value} K"
           }
        },
        series: [
          {
            name: "Series A",
            type: "bar",
            data: [11, 11, 15, 13, 12, 13, 10]
          }
        ]
      }
    };
  }
};
</script>

我应该如何消除这些错误。欲了解更多信息,请让我知道。谢谢!

vuejs2 echarts vue-cli-3
1个回答
0
投票

我终于结束了与解决方案,因为我们不能混用CommonJS的&ES模块出现此错误。为了解决这个我更新了babel.config.js文件:

// babel.config.js

module.exports = {
  presets: [
    ["@vue/app", {
      modules: "commonjs"
    }]
  ]
};

通过添加上面的代码,你的所有ES模块代码将transpiled到CommonJS的,然后传递给的WebPack编译。

© www.soinside.com 2019 - 2024. All rights reserved.