Skip to content

Commit

Permalink
🐛 [doc] reset scrollBar after switching page route (#72)
Browse files Browse the repository at this point in the history
fix #71
  • Loading branch information
QJvic authored Feb 23, 2024
1 parent f233011 commit 0ee1227
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
7 changes: 7 additions & 0 deletions doc/compositions/entry/useResetScroll.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export function useResetScroll(domRef: Ref<HTMLElement | null>) {
const route = useRoute();
watch(() => route.path, async () => {
await nextTick();
domRef.value?.scroll(0, 0);
});
}
6 changes: 4 additions & 2 deletions doc/pages/docs.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<div class="docs menu-right m-scroll">
<div class="docs menu-right m-scroll" ref="contentRef">
<NuxtPage/>
</div>
</template>
Expand All @@ -13,8 +13,10 @@
*
* 公司的业务千篇一律,复杂的代码好几百行。
*/
import { useResetScroll } from '@/compositions/entry/useResetScroll';
const contentRef = ref<HTMLDivElement | null>(null);
useResetScroll(contentRef);
</script>

<style scoped>
Expand Down
5 changes: 4 additions & 1 deletion doc/pages/main.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<div class="home menu-right m-scroll">
<div class="home menu-right m-scroll" ref="contentRef">
<NuxtPage/>
</div>
</template>
Expand All @@ -13,7 +13,10 @@
*
* 公司的业务千篇一律,复杂的代码好几百行。
*/
import { useResetScroll } from '@/compositions/entry/useResetScroll';
const contentRef = ref<HTMLDivElement | null>(null);
useResetScroll(contentRef);
</script>

<style scoped>
Expand Down

0 comments on commit 0ee1227

Please sign in to comment.