[Vuejs]-Vuejs count number of v-show elements

2👍

You can get the children of a component via:

  • this.$children
  • Or, query the child elements via this.$el.querySelector(...)
    • If you want the underlying vue component add the elements have a __vue__ propertiey
  • Or, through the ref attribute and access it via 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.

Leave a comment