我无法解决错误“SyntaxError Unexpected token 'export'。我使用的是 vue-echarts 6.0.0-beta.5 echarts 5.0.2 和 nuxt 2.15.4。我的 echarts v4 在其中运行良好nuxt 已经,我正在尝试让 echarts 5 正常工作,以便我可以升级,因为一些功能非常好。
如果我已经在一个单独的网页上,我可以导航到它。如果我刷新页面或使用图表直接转到页面,我会收到此错误。
可以在 here 中找到该问题的一个工作示例。或者,如果转到 invalid link 并选择链接以导航到主页,则图表将出现,直到页面刷新。
我可以在错误状态中找到的所有内容,以确保我的 nuxt.config.js 中有以下代码并没有解决问题。
build: {
transpile: ['vue-echarts']
}
我使用的是 vue-charts 示例。
<template>
<client-only>
<v-chart class="chart" :option="option" />
</client-only>
</template>
<script>
import { use } from "echarts/core";
import { CanvasRenderer } from "echarts/renderers";
import { PieChart } from "echarts/charts";
import {
TitleComponent,
TooltipComponent,
LegendComponent,
} from "echarts/components";
import ECharts, { THEME_KEY } from "vue-echarts";
use([
CanvasRenderer,
PieChart,
TitleComponent,
TooltipComponent,
LegendComponent,
]);
export default {
components: { "v-chart": ECharts },
provide: {
[THEME_KEY]: "dark",
},
data() {
return {
option: {
title: {
text: "Traffic Sources",
left: "center",
},
tooltip: {
trigger: "item",
formatter: "{a} <br/>{b} : {c} ({d}%)",
},
legend: {
orient: "vertical",
left: "left",
data: [
"Direct",
"Email",
"Ad Networks",
"Video Ads",
"Search Engines",
],
},
series: [
{
name: "Traffic Sources",
type: "pie",
radius: "55%",
center: ["50%", "60%"],
data: [
{ value: 335, name: "Direct" },
{ value: 310, name: "Email" },
{ value: 234, name: "Ad Networks" },
{ value: 135, name: "Video Ads" },
{ value: 1548, name: "Search Engines" },
],
emphasis: {
itemStyle: {
shadowBlur: 10,
shadowOffsetX: 0,
shadowColor: "rgba(0, 0, 0, 0.5)",
},
},
},
],
},
};
},
};
</script>
<style scoped>
.chart {
height: 400px;
}
</style>