refactor(composables): 改进页面滚动锁定逻辑并修复潜在问题

确保在客户端插件加载完成后再获取 Lenis 实例
修复组件卸载时可能的状态不一致问题
将 useHead 配置整合到 usePageScrollLock 中
This commit is contained in:
2026-04-27 02:51:45 +08:00
parent a353322454
commit dba0c18001
3 changed files with 23 additions and 22 deletions
+3 -3
View File
@@ -1,5 +1,5 @@
<script setup lang="ts">
import { ref, onMounted, onBeforeUnmount } from 'vue'
import { ref, onMounted, onBeforeUnmount, computed } from 'vue'
import gsap from 'gsap'
import { useAppStore } from '~/stores/app'
import { usePageScrollLock } from '~/composables/usePageScrollLock'
@@ -8,8 +8,8 @@ const loaderRef = ref<HTMLElement | null>(null)
const loaderBarRef = ref<HTMLElement | null>(null)
const appStore = useAppStore()
// 加载期间锁定页面滚动
usePageScrollLock(appStore.isAppLoading)
// 加载期间锁定页面滚动(注意:Pinia 的 state 是自动解包的,必须用 computed 包装才能保持响应式)
usePageScrollLock(computed(() => appStore.isAppLoading))
let loaderTween: gsap.core.Tween | null = null
let removeLoadListener: (() => void) | null = null