João Saro
João Saro

Reputation: 543

Vue count item iterated by v-for with function

I have a loop component runned by a function to filter by inputs and selects. Can I get a reactive number of elements renderized by this filter?

<component-list class=""v-for="(item, index) in itemsFilters()" :key="index" :propId="item.id"
></component-list>

itemsFilter() returns a filter of an object array by selects and inputs. I have a pen with an example of this situation: https://codepen.io/joaosaro/pen/baXgjG

Upvotes: 2

Views: 3110

Answers (1)

user320487
user320487

Reputation:

If itemsFilter is either computed or a method:

 computed: {
      itemsCount () {
          // itemsFilters is computed 
          return this.itemsFilters.length
          // or a method
          return this.itemsFilters().length
      }
  }

Upvotes: 3

Related Questions