Adding a Scroll to top feature in Vue
Posted on: March 03, 2021 by Prince Chukwudire
In this article, you will learn how to add a scroll to top feature in Vue router.
To achieve this we would need to create a method :
methods:{
moveUp(){
window.scrollTo(0,0);
}
}
and then add it to our router link:
<div>
<router-link to @click="moveUp"></router-link>
</div>
We can also achieve this by adding the following method to our router file, directly under the routes array.
scrollBehavior() {
document.getElementById('app').scrollIntoView();
}
Share on social media
//