diff --git a/src/utils/hooks/useBase.ts b/src/utils/hooks/useBase.ts deleted file mode 100644 index abf7c2b..0000000 --- a/src/utils/hooks/useBase.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { onActivated, onDeactivated } from 'vue' - -export function useBase() { - const mainScroll = $ref() - const mainScrollTop = $ref(0) - onActivated(() => { - console.log('onActivated') - }) - - onDeactivated(() => { - console.log('onDeactivated') - }) -} diff --git a/src/utils/hooks/useScroll.ts b/src/utils/hooks/useScroll.ts new file mode 100644 index 0000000..e3989ff --- /dev/null +++ b/src/utils/hooks/useScroll.ts @@ -0,0 +1,17 @@ +import { onActivated, onDeactivated, ref } from 'vue' + +export function useScroll() { + const mainScroll = ref() + let mainScrollTop = $ref(0) + onActivated(() => { + if (mainScroll.value && mainScroll.value.wrapper) { + mainScroll.value.wrapper.scrollTop = mainScrollTop + } + }) + onDeactivated(() => { + if (mainScroll.value && mainScroll.value.wrapper) { + mainScrollTop = mainScroll.value.wrapper.scrollTop + } + }) + return mainScroll +}