Function useResizeObserver

  • 观察一个或多个元素的尺寸变化,并在变化时执行指定的回调函数。

    Parameters

    Returns ResizeObserverReturn

    Example

    <script setup lang="ts">
    import { useResizeObserver } from "@eqian/utils-vue";
    import {Ref, ref} from "vue";
    const div1 = ref<HTMLElement>()
    const {stop, start} = useResizeObserver(div1 as Ref<HTMLElement>, ({entries})=> {
    console.log('尺寸变化', entries)
    })
    </script>

    <template>
    <div>
    <div style="min-height: 100px;min-width: 100px" contenteditable ref="div1" />
    <button @click="()=>start()">开始</button>
    <button @click="()=>stop()">关闭</button>
    </div>
    </template>