From 9eb2206fc2945eacdca536d9dfb21e1ecff5c314 Mon Sep 17 00:00:00 2001 From: yms Date: Wed, 8 Jan 2025 16:47:14 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MapView/index.tsx | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/MapView/index.tsx b/MapView/index.tsx index 37a3733..f522400 100644 --- a/MapView/index.tsx +++ b/MapView/index.tsx @@ -51,6 +51,7 @@ const MapView: React.ForwardRefRenderFunction< const { run } = useDebounceFn( () => { + console.log('屏幕变化,重新计算'); if (!containerRef.current) return; const { width, height } = containerRef.current?.getBoundingClientRect(); setMapSize({ @@ -69,15 +70,13 @@ const MapView: React.ForwardRefRenderFunction< * 重新设置地图容器宽高 */ useEffect(() => { - const observer = new ResizeObserver(() => { - run(); - }); - observer.observe(document.body); + run(); + window.addEventListener('resize', run); // 清理函数,停止观察 return () => { - observer.unobserve(document.body); + window.removeEventListener('resize', run); }; - }, []); + }, [containerRef.current]); const [isReady, { setFalse, setTrue }] = useBoolean(false); -- GitLab