This content originally appeared on CodeSource.io and was authored 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();
}
The post Adding a Scroll to top feature in Vue appeared first on CodeSource.io.
This content originally appeared on CodeSource.io and was authored by Prince Chukwudire
Prince Chukwudire | Sciencx (2021-03-03T16:51:16+00:00) Adding a Scroll to top feature in Vue. Retrieved from https://www.scien.cx/2021/03/03/adding-a-scroll-to-top-feature-in-vue/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.