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

283
Views
¿Cuál es la forma correcta de volver a renderizar un componente de otro [Vue.js]?

he 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>

y componente gráfico

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

La función getValuesFromDate($event) llama a la 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) {} }

Cuando cambio la selección (y llamo a esta función), vuelvo a renderizar graph-component cambiando la clave, y funciona bien. ¿Cuál es la forma mejor y más correcta de hacer esto o esta es lo suficientemente buena?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

@Lube, esta es la mejor manera de forzar una nueva representación de un componente. Necesitaba hacer lo mismo con los componentes de gráficos en el pasado cuando cambiaban mis datos.

Hay un excelente artículo al que he vinculado a continuación que explica las diversas formas de forzar una nueva representación, pero en última instancia, la mejor manera es agregar una propiedad :key a su componente y actualizar esa clave cada vez que necesite una nueva representación.

El artículo se puede encontrar aquí .

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