[Vuejs]-How to get height of div with Vue

-1👍

Whenever you’re getting information from the DOM like this, it’s advantageous to use computed properties:

  computed: {
    height () {
      return this.$refs.infoBox.clientHeight
    }
  }

This way Vue polls for changes to this variable and it’ll be updated as the DOM updates. The problem with setting it once in mounted is that this obviously doesn’t happen. Other then that you’re grabbing it the right way. If it’s a hardcoded height set in CSS you could also grab it out of the style object, but that’s not a great idea.

Leave a comment