Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

199
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda