From 733611e00b06c1b1a6b46d559f94d25b385b03df Mon Sep 17 00:00:00 2001 From: xingyu Date: Thu, 27 Apr 2023 16:35:25 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E6=B0=B4=E5=8D=B0?= =?UTF-8?q?=E9=87=8D=E5=A4=8D=E5=8F=A0=E5=8A=A0=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/hooks/web/useWatermark.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/hooks/web/useWatermark.ts b/src/hooks/web/useWatermark.ts index 4a24da0a..a8e0b854 100644 --- a/src/hooks/web/useWatermark.ts +++ b/src/hooks/web/useWatermark.ts @@ -4,8 +4,13 @@ import { addResizeListener, removeResizeListener } from '@/utils/event' import { isDef } from '@/utils/is' const domSymbol = Symbol('watermark-dom') +const sourceMap = new WeakMap() export function useWatermark(appendEl: Ref = ref(document.body) as Ref) { + const appendElRaw = unref(appendEl) + if (appendElRaw && sourceMap.has(appendElRaw)) { + return sourceMap.get(appendElRaw) + } const func = useRafThrottle(function () { const el = unref(appendEl) if (!el) return @@ -80,6 +85,7 @@ export function useWatermark(appendEl: Ref = ref(document.bo const { clientHeight: height, clientWidth: width } = el updateWatermark({ str, width, height }) el.appendChild(div) + sourceMap.set(el, { setWatermark, clear }) return id }