From 1f5b77406adf1bf51b02331cb0e22654763faa8e Mon Sep 17 00:00:00 2001 From: "tangly1024.com" Date: Mon, 3 Jun 2024 18:02:09 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8A=A8=E6=95=88=E7=A7=BB=E5=8A=A8=E7=AB=AF?= =?UTF-8?q?=E7=89=B9=E6=AE=8A=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/Fireworks.js | 6 +++++- components/MouseFollow.js | 20 +++++++++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/components/Fireworks.js b/components/Fireworks.js index cb6a2d98..e61585f1 100644 --- a/components/Fireworks.js +++ b/components/Fireworks.js @@ -35,7 +35,11 @@ const Fireworks = () => { loadFireworks() return () => { - // 在组件卸载时清理资源(如果需要) + // 在组件卸载时清理资源 + const fireworksElements = document.getElementsByClassName('fireworks') + while (fireworksElements.length > 0) { + fireworksElements[0].parentNode.removeChild(fireworksElements[0]) + } } }, []) diff --git a/components/MouseFollow.js b/components/MouseFollow.js index 2215a0ce..cc10d29c 100644 --- a/components/MouseFollow.js +++ b/components/MouseFollow.js @@ -15,8 +15,26 @@ const MOUSE_FOLLOW = () => { loadExternalResource('/js/mouse-follow.js', 'js').then(url => { window.createMouseCanvas && window.createMouseCanvas()({ type, color }) }) + + return () => { + // 在组件卸载时清理资源 + const mouseFollowElement = document.getElementById('vixcityCanvas') + mouseFollowElement?.parentNode?.removeChild(mouseFollowElement) + } }, []) - return <> + return ( + <> + + + ) } export default MOUSE_FOLLOW