Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

170
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!