Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

197
Vistas
Why doesn't this simple data initialisation function work in this vue component?

I have a vue 3 component. The relevant script code below;

<script>
/* eslint-disable */

export default {
  name: "BarExample",
  data: dataInitialisation,
  methods: {
    updateChart,
  }
};

function dataInitialisation()
{
  return {
      chartOptions: {
        plotOptions: {
          bar: {
            horizontal: true
          }
        },
        xaxis: {
          //categories: [1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999],
          categories: [1991, 1992],
        }
      },
      series: [
        {
          name: "series-1",
          data: [30, 40],
        }
      ]
    };
}
</script>

The above code works fine.

However, if I were to modify the function dataInitialisation() code into this;

function dataInitialisation()
{
  init_data = {
      chartOptions: {
        plotOptions: {
          bar: {
            horizontal: true
          }
        },
        xaxis: {
          //categories: [1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999],
          categories: [1991, 1992],
        }
      },
      series: [
        {
          name: "series-1",
          data: [30, 40],
        }
      ]
    };

  return init_data;
}

With the function above, the vue website turned blank and no error message appeared. What is wrong? Both functions look pretty much the same to me.

EDIT: I noticed another strange behaviour. I added a meaningless line x=2 to the function and this caused the website to go blank too.

function dataInitialisation()
{
  x = 2; //meaningless line caused website to go blank

  return {
      chartOptions: {
        plotOptions: {
          bar: {
            horizontal: true
          }
        },
        xaxis: {
          //categories: [1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999],
          categories: [1991, 1992],
        }
      },
      series: [
        {
          name: "series-1",
          data: [30, 40],
        }
      ]
    };
}
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I will answer my own question. I got the answer thanks to @3limin4t0r in the comment section.

I made a rookie mistake. I forgot the let in front of the variable init_data. There was no error message in javascript.

function dataInitialisation() {
  let init_data = {
    chartOptions: {
      plotOptions: {
        bar: {
          horizontal: true,
        },
      },
      xaxis: {
        //categories: [1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999],
        categories: [1991, 1992],
      },
    },
    series: [
      {
        name: "series-1",
        data: [30, 40],
      },
    ],
  };

  return init_data;
}
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda