fix:优化重进比赛tips展示逻辑

This commit is contained in:
2026-05-13 11:17:30 +08:00
parent 6d434e89ab
commit 6cb5288631
3 changed files with 25 additions and 2 deletions

View File

@@ -102,6 +102,14 @@ watch(() => store.game.totalShot, (newVal) => {
}
}, { immediate: true });
// 监听 Pinia store 中 tips 变化,用于比赛恢复时同步提示文案(替代 uni.$emit 避免时序问题)
// 使用 immediate: true 确保组件创建时立即读取 store 当前值(解决 onShow 早于 onMounted 导致 uni.$emit 事件丢失的问题)
watch(() => store.game.tips, (newVal) => {
if (newVal) {
tips.value = newVal;
}
}, { immediate: true });
onMounted(() => {
uni.$on("update-tips", onUpdateTips);
uni.$on("socket-inbox", onReceiveMessage);
@@ -111,6 +119,8 @@ onMounted(() => {
onBeforeUnmount(() => {
uni.$off("socket-inbox", onReceiveMessage);
uni.$off("play-sound", playSound);
// 补充取消 update-tips 监听,防止页面重建时监听器叠加
uni.$off("update-tips", onUpdateTips);
if (timer.value) clearInterval(timer.value);
});
</script>