hookehuyr

fix: 在组件卸载时清理定时器防止内存泄漏

...@@ -63,6 +63,14 @@ const is_wx = computed(() => wxInfo().isWeiXin); ...@@ -63,6 +63,14 @@ const is_wx = computed(() => wxInfo().isWeiXin);
63 // iframe模式判断 63 // iframe模式判断
64 const is_iframe = computed(() => window.self !== window.top); 64 const is_iframe = computed(() => window.self !== window.top);
65 65
66 +// 组件卸载时清理定时器(必须在 setup 同步阶段注册钩子)
67 +let upDater = null;
68 +onUnmounted(() => {
69 + if (upDater) {
70 + upDater.destroy();
71 + }
72 +});
73 +
66 onMounted(async () => { 74 onMounted(async () => {
67 // 重置弹框状态,确保每次访问页面时都能正常显示未完成表单弹框 75 // 重置弹框状态,确保每次访问页面时都能正常显示未完成表单弹框
68 resetDialogState(); 76 resetDialogState();
...@@ -242,7 +250,6 @@ onMounted(async () => { ...@@ -242,7 +250,6 @@ onMounted(async () => {
242 } 250 }
243 251
244 // TAG:检查是否更新 252 // TAG:检查是否更新
245 - let upDater = null;
246 if (import.meta.env.PROD) { 253 if (import.meta.env.PROD) {
247 upDater = new Updater({ 254 upDater = new Updater({
248 time: 30000 255 time: 30000
...@@ -261,12 +268,6 @@ onMounted(async () => { ...@@ -261,12 +268,6 @@ onMounted(async () => {
261 }) 268 })
262 } 269 }
263 270
264 - // 组件卸载时清理定时器
265 - onUnmounted(() => {
266 - if (upDater) {
267 - upDater.destroy();
268 - }
269 - });
270 }); 271 });
271 </script> 272 </script>
272 273
......