ResizeObserver使用

2024-01-23  本文已影响0人  喜欢走弯路的人

HTML:

<div class="main" ref="main" style="width:200px;height:200px;background:green;">

      <chatView></chatView>

</div>

CSS:

.main {

    resize: both;

    overflow: auto;

}

JS:

    mounted(){

      // (1) 定义被观察的目标对象

      let main=this.$refs.main

      // (2)定义一个观察者 观察 目标对象的变化

      const resizeObserver = new ResizeObserver((entries)=>{

        for(let entry of entries){

          console.log(entry.contentRect,'===entrys====')

        }

      })

      // (3)观察者观察目标对象

      resizeObserver.observe(main);

    },

上一篇 下一篇

猜你喜欢

热点阅读