From 47fd2b6d005898bb36d14319906ed3424c0c98d4 Mon Sep 17 00:00:00 2001 From: cuixiaorui Date: Wed, 24 Jul 2024 18:53:50 +0800 Subject: [PATCH] refactor: optimize start trace learn time --- apps/client/components/main/Game.vue | 9 +-------- apps/client/components/main/LearningTimer.vue | 13 +++++++++++++ 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/apps/client/components/main/Game.vue b/apps/client/components/main/Game.vue index 7ade251b..a4d1282a 100644 --- a/apps/client/components/main/Game.vue +++ b/apps/client/components/main/Game.vue @@ -14,22 +14,15 @@ diff --git a/apps/client/components/main/LearningTimer.vue b/apps/client/components/main/LearningTimer.vue index eb941d46..40c02b8f 100644 --- a/apps/client/components/main/LearningTimer.vue +++ b/apps/client/components/main/LearningTimer.vue @@ -62,6 +62,19 @@ watch(totalSeconds, (newValue) => { } }); +// 因为这个组件是放在 game.vue 中的 +// 所以生命周期是跟着 game 一起的 +// 所以我们在这里启动 tracking 等于同游戏开始的时候启动 游戏结束的时候停止 +// 放在这里的原因是在 game.vue 里面控制了 learningTimer 的渲染 +// 所以对于 startTracking 就不需要在做额外的判断了 +onMounted(() => { + startTracking(); +}); + +onUnmounted(() => { + stopTracking(); +}); + function handleVisibilityChange() { if (document.hidden) { stopTracking();