M
M
MeMoJlor2021-09-30 21:54:02
Vue.js
MeMoJlor, 2021-09-30 21:54:02

How to get block height dynamically in vue?

Hello, tell me how to get the block height dynamically? setInterval comes to mind, but I think it's a bad idea. Also, does it make sense to use computed instead of methods?

<template>
  <section ref='height'>
    <div class="slider-text">
      <h1>TEXT</h1>
      <span>lorem ipsum</span>
    </div>
  </section>
</template>

<script>
export default {

  name: 'MainSlider',
  data () {
    return {
    }
  },
  methods: {
    watchHeight() {
      console.log(this.$refs.height.clientHeight)
    }
  },
  mounted(){
    this.watchHeight() 
  }
}
</script>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Arseny, 2021-10-01
@MeMoJlor

Attach a listener to block change conditions, such as window resize, and don't forget to remove it when the component is unmounted. If events occur frequently and uncontrollably, then you can start using a debouncer .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question