nuxt.js:窗口未定义apexcharts/vue-apexcharts
我添加了这个简单的示例,来自 apexcharts.com 。可以肯定的是,进口是正确的。我没有在任何地方引用窗口。添加此文件时,我的整个应用程序只是停顿。我相信这与SSR或NUXT配置有关。
<template>
<div id="chart">
<apexchart
type="donut"
width="380"
:options="chartOptions"
:series="series"
></apexchart>
</div>
</template>
<script>
import VueApexCharts from "vue-apexcharts";
export default {
name: "Donut",
components: {
apexchart: VueApexCharts,
},
data() {
return {
data: {
series: [44, 55, 41, 17, 15],
chartOptions: {
chart: {
type: "donut",
},
responsive: [
{
breakpoint: 480,
options: {
chart: {
width: 200,
},
legend: {
position: "bottom",
},
},
},
],
},
},
};
},
};
</script>
I have added this simple example from apexcharts.com. Pretty sure the imports are correct. I am not referencing window anywhere. My whole app just come to a halt when adding this file. I believe it has to do with the SSR or Nuxt configs.
<template>
<div id="chart">
<apexchart
type="donut"
width="380"
:options="chartOptions"
:series="series"
></apexchart>
</div>
</template>
<script>
import VueApexCharts from "vue-apexcharts";
export default {
name: "Donut",
components: {
apexchart: VueApexCharts,
},
data() {
return {
data: {
series: [44, 55, 41, 17, 15],
chartOptions: {
chart: {
type: "donut",
},
responsive: [
{
breakpoint: 480,
options: {
chart: {
width: 200,
},
legend: {
position: "bottom",
},
},
},
],
},
},
};
},
};
</script>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如我的链接答案(最后一句话,带有直接组件语法) :
我还删除了一个已经嵌套整个配置的
data
已经嵌套了data()
的内部。如浏览器控制台错误所示,这导致了不匹配的道具。As explained in my linked answer (last sentence, with the direct component syntax), here is how you make a proper working setup:
I've also removed a
data
who was nesting the whole configuration, already inside ofdata()
. This was causing a non-match in terms of props as shown in the browser console errors.将您的组件包装在NUXT的
&lt;仅客户端&gt;
组件中。试图引用不存在的窗口
对象时,这将阻止SSR/SSG破坏。例如
Wrap your component in nuxt's
<client-only>
component. That will prevent SSR/SSG breaking when attempting to reference the nonexistentwindow
object.E.g.