Vue Js Scroll to Top of Page

Vue.Js Scroll to the top of the page: Vue.js makes it easy to scroll to the top of a page using the JavaScript method window. scrollTo(x,y) . You can use the native JavaScript functions window. scrollTo('0',0') function in vue.js To scroll the top of page on click the button.

written

reviewed

updated

Thanks for your feedback!
Your contributions will help us to improve service.
How to Use Vue JS to Scroll to the Top of a Page
With Vue.js, scrolling to the top of a page can be easily achieved using the v-on directive to call a method that uses the window.scrollTo(0,0) method
Vue Js Scroll Top of Page
Copied to Clipboard
18
<div id="app">
<button @click="scrollTop" style="position:fixed">Top</button><br>
</div>
<script type="module">
import { createApp } from "vue";
createApp({
data() {
return {
top: 0,
}
},
methods: {
scrollTop() {
window.scrollTo(0, this.top);
}
}
}).mount("#app");
</script>
Output of above example
Ad