I would like my page to scroll to the top before changing to another tab. I have tried the following code but in vain.
<b-collapse id="nav-collapse" is-nav>
<b-navbar-nav class = "ml-5">
<b-nav-item :active= "$route.matched.some(({ name }) => name === 'tab1')" class = "navitem" @click= "routehome">tab1</b-nav-item>
<b-nav-item :active= "$route.matched.some(({ name }) => name === 'tab2')" class = "navitem" @click= "routeproject">tab</b-nav-item>
<b-nav-item :active= "$route.matched.some(({ name }) => name === 'tab3')" class = "navitem" @click= "routeexperience">tab3</b-nav-item>
</b-navbar-nav>
<b-collapse id="nav-collapse" is-nav>
in script i tried adding this but it doesnt show the animation as the code is running asynchronously.
totab1() {
window.scrollTo(0, 0);
this.$router.push("/tab1");
},
totab2() {
window.scrollTo(0, 0);
this.$router.push("/tab2");
},
I then tried adding then function but it seems like windows.scroll(0,0) doesnt support then. Is there a way to work around this?
totab3() {
window.scrollTo(0, 0).then(() => {
this.$router.push("/tab3");
})
}