From eff3277513ff525495053e642a77f468cd9046b9 Mon Sep 17 00:00:00 2001 From: zyronon Date: Fri, 3 May 2024 17:03:46 +0800 Subject: [PATCH] refactor: fixed the problem that the scroll component could not remember the height --- src/utils/hooks/useBase.ts | 13 ------------- src/utils/hooks/useScroll.ts | 17 +++++++++++++++++ 2 files changed, 17 insertions(+), 13 deletions(-) delete mode 100644 src/utils/hooks/useBase.ts create mode 100644 src/utils/hooks/useScroll.ts 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 +}