Nuxt.js: window is not defined apexcharts/vue-apexcharts
P粉366946380
P粉366946380 2023-11-09 22:07:08
0
2
557

I added this simple example from apexcharts.com. Pretty sure the import is correct. I don't reference window anywhere. When adding this file my entire application stops. I believe this has something to do with SSR or Nuxt configuration.

<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>


P粉366946380
P粉366946380

reply all(2)
P粉946437474

Wrap your component in nuxt's <client-only> component. This will prevent SSR/SSG from breaking when trying to reference a non-existent window object.

For example


  

P粉834840856

As explained in my linked answer (last sentence, using direct component syntax), here's how to make a correct working setup:



sssccc

I also removed a data which nested the entire configuration, already inside data(). This resulted in a props mismatch, as shown in the browser console error.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!