File tree Expand file tree Collapse file tree 4 files changed +22
-15
lines changed
Expand file tree Collapse file tree 4 files changed +22
-15
lines changed Original file line number Diff line number Diff line change 2121<script setup lang="ts">
2222import { computed } from " vue" ;
2323
24+ import { scrollToTop } from " @/utils" ;
2425import { useValidationStore } from " @/store" ;
2526import CustomButton from " @/components/simple/CustomButton.vue" ;
2627
@@ -42,7 +43,6 @@ function setStep(index: number): void {
4243 throw new Error (" step out of range" );
4344 }
4445
45- const appElement = document .getElementById (" base-container" );
46- if (appElement !== null ) appElement .scrollTop = 0 ;
46+ scrollToTop ();
4747}
4848 </script >
Original file line number Diff line number Diff line change 2121<script lang="ts" setup>
2222import { useRouter , useRoute } from ' vue-router'
2323
24+ import { scrollToTop } from " @/utils" ;
2425import { useTrainingStore } from " @/store" ;
2526import CustomButton from ' @/components/simple/CustomButton.vue'
2627
2728const router = useRouter ()
2829const trainingStore = useTrainingStore ()
2930const route = useRoute ()
3031
31- function scrollToTop() {
32- const appElement = document .getElementById (' base-container' );
33- if (appElement !== null ) appElement .scrollTop = 0 ;
34- }
35-
3632async function prevStepOrList(): Promise <void > {
37- if (trainingStore .step === 1 ) {
38- await router .push ({ path: ' /list' });
39- } else {
40- trainingStore .prevStep ();
41- scrollToTop (); // scroll manually
42- }
33+ if (trainingStore .step === 1 ) {
34+ await router .push ({ path: ' /list' });
35+ trainingStore .prevStep ();
36+ } else {
37+ trainingStore .prevStep ();
38+ scrollToTop (); // scroll manually
39+ }
4340}
4441
4542function nextStep() {
Original file line number Diff line number Diff line change 11import createDebug from "debug" ;
22import { createRouter , createWebHashHistory } from 'vue-router'
3+ import { scrollToTop } from "@/utils" ;
34
45import TrainingBar from '@/components/progress_bars/TrainingBar.vue'
56import TestingBar from '@/components/progress_bars/TestingBar.vue'
@@ -19,8 +20,7 @@ const router = createRouter({
1920 // Always scroll to top when navigating to a new page
2021 // Because router is wrapped in a BaseLayout, returning { top: 0 } doesn't do anything
2122 // https://github.com/vuejs/vue-router/issues/3451#issuecomment-975637797
22- const containerId = document . getElementById ( 'base-container' ) ;
23- if ( containerId ) containerId . scrollTop = 0 ;
23+ scrollToTop ( ) ;
2424 return { top : 0 }
2525 } ,
2626 routes : [
Original file line number Diff line number Diff line change 1+ /**
2+ * Instantly scrolls to the top of the page without animation.
3+ * Because router is wrapped in a BaseLayout, window.scrollTo({ top: 0 }) doesn't work.
4+ */
5+ export function scrollToTop ( ) {
6+ const appElement = document . getElementById ( 'base-container' ) ;
7+ if ( appElement !== null ) {
8+ appElement . scrollTop = 0 ;
9+ }
10+ }
You can’t perform that action at this time.
0 commit comments