scroll to element after route load in vue code example
Example 1: scroll to top vue
<a @click="scrollToTop(), goToPricing()">Pricing</a>
methods: {
scrollToTop() {
window.scrollTo(0, 0);
}, goToPricing() {
this.$router.push('/pricing');
}
}
Example 2: scroll to top router link vue
export default new Router({
scrollBehavior() {
return { x: 0, y: 0 };
},
routes: [
{
path: '/',
name: 'Home',
component: Home
}
],
mode: 'history'
});
Example 3: scroll to top router link vue
scrollBehavior(to, from, savedPosition) { return { x: 0, y: 0 };}