A
A
andrei_pro2019-05-09 20:44:05
Vue.js
andrei_pro, 2019-05-09 20:44:05

How to track the size of an element?

Hello.
There is a div in it table:

<div :style="{ width : table.width || 100 }">
<table>
  <tr>
    <td><input type="text" v-model="table.text" /></td>
  </tr>
</table>
</div>

When I fill in the input - the offsetWidth of the table changes. You need to set the width of the divs to the size of the table. I don’t want to hang up the change event on the input, there are a dozen of them in the table. How to find out that the offsetWidth of the table has changed?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
andrei_pro, 2019-05-09
@andrei_pro

Solved the problem. Put ResizeObserver

S
Sergey Turetsky, 2019-05-09
@pfffffffffffff

data: function (){return{
  lastWidth: -1
}}
mount: function() {
  const el = #find
  this.lastWidth = el.offsetWidth
  setInterval(function(){
    if (this.lastWidth != el.offsetWidth) {
      // TODO
    }
  }, 500)
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question