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

387
Views
What is correct way to re-render one component from another [Vue.js]

I have select:

  <select @change="getValuesFromDate($event)">
                        <option value="1">Last 24 hours</option>
                        <option value="7">Last7 days</option>
                        <option value="30">Last 30 days</option>
                        <option>Custom date</option>
                    </select>

and chart component

                          <graph-component
                                :key="graphKey"
                                v-bind="measurement"
                                :value="valueOfMeasurement(measurement)"
                                :time_date="dateOfMeasurement()"
                            ></graph-component>

Function getValuesFromDate($event) calls API:

   getValuesFromDate(event) {
        let apiLink ="https://api.thingspeak.com/channels/1111111/feeds.json?api_key=XXXXXXXXXXXX&days=" +event.target.value +"&round=2&average=";
        let preferableSize = 0;
        if (event.target.value == 1) {
            preferableSize = 60;
        } else {
            preferableSize = 1440;
        }
        try {
            axios
                .get(apiLink + preferableSize, {
                    withCredentials: false
                })
                .then(response => {
                    this.message = response.data;
                });
            this.graphKey+= 1;
        } catch (error) {}
    }

When I change select (and call this function) I re-render graph-component by changing it key, and it works just fine. What is better and more correct way to do this or this one is fine enough?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

@Lube this is the best way to force a re-render of a component. I've needed to do the same for graph components in the past when my data changes.

There's a great article I've linked to below that explains the various ways of forcing a re-render, but ultimately the best way is adding a :key property to your component and updating that key whenever you need a re-render.

Article can be found here.

over 4 years ago · Santiago Trujillo Report
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!