From 5a8e1e5af79af9841c078ff1faf88511ffd40dcd Mon Sep 17 00:00:00 2001 From: wangxiaoshuang <825034831@qq.com> Date: Mon, 2 Feb 2026 11:04:44 +0800 Subject: [PATCH] =?UTF-8?q?=E7=B3=BB=E7=BB=9F=E6=97=B6=E9=97=B4=E7=9A=84?= =?UTF-8?q?=E5=AE=9A=E4=BD=8D=EF=BC=8C=E5=BA=94=E8=AF=A5=E6=A0=B9=E6=8D=AE?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=E5=99=A8=E7=9A=84=E5=88=86=E5=88=AB=E7=8E=87?= =?UTF-8?q?=E5=8F=AF=E4=BB=A5=E9=80=82=E9=85=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/timeTag/index.vue | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/components/timeTag/index.vue b/src/components/timeTag/index.vue index 6bece77b..6c2bf40d 100644 --- a/src/components/timeTag/index.vue +++ b/src/components/timeTag/index.vue @@ -9,13 +9,28 @@ export default { return { time: '', timer: null, - suggestionTextColor: '#909399' + suggestionTextColor: '#909399', + resizeObserver: null } }, created() { this.getTime() }, async mounted() { + this.resizeObserver = new ResizeObserver(entries => { + entries.forEach(entry => { + // 获取元素的新尺寸 + // const { width, height } = entry.contentRect; + // console.log(`元素宽度:${width}px, 高度:${height}px`); + // 在此可以将宽高值保存到 data 中 + // this.elementWidth = width; + // this.elementHeight = height; + this.dragDoc() + }); + }); + const body = document.getElementsByTagName('body')[0] + // 开始监听指定元素 + this.resizeObserver.observe(body); this.dragDoc() this.setColor() }, @@ -102,6 +117,9 @@ export default { clearInterval(this.timer) this.timer = null } + if (this.resizeObserver) { + this.resizeObserver.disconnect(); + } } }