From 9784cdc840336d5c2bb006fa3ababfa7fa4056af Mon Sep 17 00:00:00 2001 From: joeguang Date: Thu, 11 Apr 2024 14:36:24 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E4=BC=98=E5=8C=96=E6=B0=B4=E5=8D=B0?= =?UTF-8?q?=E5=9C=A8=E6=8E=A7=E5=88=B6=E5=8F=B0=E5=8F=AF=E4=BB=A5hide?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98=20(#3732)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/hooks/web/useWatermark.ts | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/hooks/web/useWatermark.ts b/src/hooks/web/useWatermark.ts index 68c820b7c..671cedfa9 100644 --- a/src/hooks/web/useWatermark.ts +++ b/src/hooks/web/useWatermark.ts @@ -93,16 +93,15 @@ const obFn = () => { target?.parentElement?.appendChild(node as HTMLElement); } } - if (mutation.attributeName === 'style' && mutation.target) { + if (mutation.type === 'attributes' && mutation.target) { + // 修复控制台可以”Hide element” 的问题 const _target = mutation.target as HTMLElement; const target = findTargetNode(_target); if (target) { - const { waterMarkOptions = {} } = target; - resetWatermarkStyle( - _target as HTMLElement, - _target?.['data-watermark-text'], - waterMarkOptions, - ); + // 禁止改属性 包括class 修改以后 mutation.type 也等于 'attributes' + // 先解除监听 再加一下 + clearAll(); + target.setWatermark(target.targetElement?.['data-watermark-text']); } } }