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

211
Views
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 answers
Answer question

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