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

210
Vistas
Vue: Computed properties to check offsetHeight of elements not updating

I have a component that takes an array of 50 objects.

<template>
   <div v-for="(item,index) in items" ref="items" :key="index">
      //
   </div>

</template>

props: {
    items: {
      type: Array,
      required: true,
    },
}

I want to have the prop items checked for their offsetHeight so I made a computed property, grabbed the items by their ref and first tested it by returning just that.

computed: {
  allItems() {
    const all = this.$refs.items;
    return all;
  }
}

in VueTools , this shows an array of HTMLDivElement's and works as expected if I use allItems in place of items in the template.

now I want to implement the check for offsetHeight:

computed: {
  allItems() {
    const all = this.$refs.items;
    return all.filter(x => {
       x.offsetHeight > 300;
    })
  }
}

but this shows the computed property now as 15 so it filtered them but when I change the window height, the offsetHeight in the UI change but the computed property shows 15 regardless. Shouldn't this continuously show the current values?

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

0

Shouldn't this continuously show the current values?

No, because HTMLElement.offsetHeight is a native property that cannot be observed by Vue. An element's height can by changed by the browser at any time without Vue's knowledge. You have to use another means to respond to changes in an element's size, such as using ResizeObserver or listening to the window resize event.

Vue 2's reactivity system works with plain objects only. See Reactivity in Depth for more information.

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