Reputation: 1485
I need to count a number of v-show elements (cards) that are showing below:
<v-layout v-show="checkArray(offer, speciality)">
<v-flex>
<v-card>
....
<v-card>
<v-flex>
</v-layout>
this seems easy in js but how to do it in vuejs? My dom is changing dynamically due to search function, so I need to count children elements dynamically.
I've managed to use ref="", but as it is said in documentation:
"$refs are only populated after the component has been rendered, and it is not reactive. It is only meant as an escape hatch for direct child manipulation - you should avoid using $refs in templates or computed properties."
Upvotes: 0
Views: 2907
Reputation: 4481
You can get the children of a component via:
this.$children
this.$el.querySelector(...)
__vue__
propertiey this.$refs['yourRefname']
but be aware only refs in v-for
are turned into arrays.Once you've got your elements you can count them like in regular JS, if you use this.$ref
just read out the array length.
Upvotes: 2