diff --git a/app/app.vue b/app/app.vue index 12bef91..c98a649 100644 --- a/app/app.vue +++ b/app/app.vue @@ -132,16 +132,22 @@ if (import.meta.server) { } let rafId: number | null = null -let stopWatch: (() => void) | null = null onMounted(() => { useEventListener('scroll', scrollStore.updateScrollValue, { passive: true }) - stopWatch = watch( + + const { gtag, initialize } = useGtag() + initialize(gaCode.value) + gtag('event', 'screen_view', { + app_name: 'My App', + screen_name: 'Home', + }) + + watch( scrollGnbPosition, newValue => { - if (rafId) { - cancelAnimationFrame(rafId) - } + if (rafId) cancelAnimationFrame(rafId) + rafId = requestAnimationFrame(() => { document.documentElement.style.setProperty( '--scroll-stove-position', @@ -152,27 +158,11 @@ onMounted(() => { }, { immediate: true } ) - - const { gtag, initialize } = useGtag() - initialize(gaCode.value) - gtag('event', 'screen_view', { - app_name: 'My App', - screen_name: 'Home', - }) }) onBeforeUnmount(() => { - // watch 정리 - if (stopWatch) { - stopWatch() - stopWatch = null - } - // requestAnimationFrame 정리 - if (rafId) { - cancelAnimationFrame(rafId) - rafId = null - } + if (rafId) cancelAnimationFrame(rafId) })