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(); + } } }