安装
yarn add element-resize-detector
配置
vite-env.d.ts
declare module 'element-resize-detector'
使用
<template>
<div ref="boxRef"></div>
</template>
<script setup lang="ts" name="Home">
import elementResizeDetectorMaker from 'element-resize-detector'
const erd = elementResizeDetectorMaker()
const boxRef = ref('')
onMounted(() => {
erd.listenTo(boxRef.value, () => {
console.log('宽度变化了')
})
})
</script>