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.
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
<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>