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

178
Visualizações
using this. in async function

In my project I want to visualize some data that I fetched from an API on a vue3-webapp. Now I have the problem that the chart renders before I get the data from my async fetch function. So I use Key-changing according https://michaelnthiessen.com/force-re-render/. At the end of my fetch function I want to increase the counter what should lead to a re-rendering of the chart. Because of some reason I can't use the this. operator to use my counter. What can I do instead?

(re)rendering in html: <LineChart :key="counter" id="line-chart" /> exportdefault.data.return: counter: 0, exportdefault.methods:

forceRerender() {
        this.counter ++;
        },

exportdefault.mounted():

        const xTime = [];
        const yValue = [];
        const data2 = [];
        const api_url = "http://192.168.178.84:4997/wirkleistungL1";

        async function getData() {
            const response = await fetch(api_url);
            const data = await response.json();
            var result = data[0].result;
            var lastdayunix = new Date(new Date(new Date(result[result.length - 1].DateTime)).toISOString().slice(0, 10)).getTime();


                for (let i = 0; i < result.length; i++) {
                    if (result[i].DateTime >= lastdayunix) {
                    xTime.push(String(result[i].DateTime));
                    yValue.push(parseFloat(result[i].Value));
                    }
                  }
            this.forceRerender()


        }

        getData();

Error:

Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'forceRerender') at getData

about 4 years ago · Juan Pablo Isaza
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