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

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