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

222
Vistas
How to calculate array while rendering [Vue.js] - Infinite loop error

This is my code in parent component:

                   <div
                            v-for="measurement
                             in measurements"
                            :key="measurement.id"
                   >
                            <graph-component
                                :value="valueOfMeasurement(measurement)"
                            ></graph-component>
                  </div>

I send props value to child component graph-component. :value should send array to graph-component but I get error You may have an infinite update loop in a component render function..

MethodvalueOfMeasurement(measurement) is:

methods:{

     valueOfMeasurement(measurement) {
                this.arrayOfValues.length=0;
                this.counter=0;
    
                for( this.counter;this.counter<this.message.feeds.length;this.counter++)
                {
                     this.arrayOfValues.push(this.message.feeds[this.counter]["field" + measurement.fieldId]);
                }
                return this.arrayOfValues;
                
            }
}

Im beginner to Vue.js and I assume that I get this error because I push new elements to array, but I can't find other way to do this.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You're getting a possible infinite loop because you are mutating state during the render. Specifically, you are calling the valueOfMeasurement method during the render (i.e. within the template) which is modifying the component state (this.arrayOfValues and this.counter). This will trigger Vue to re-render again, which then mutates the state again, and so on infinitely.

Why are arrayOfValues and counter local state? You're just clearing them each time the method is called anyway, so it seems they should just be local variables within the method. But... that depends on if <graph-component> mutates these arrays; if so you should pre-compute all of this data ahead of time outside of the template, perhaps when measurements is first set or in created hook, etc.

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