mercs600 / vue2-perfect-scrollbar

Vue.js wrapper for perfect scrollbar
https://mercs600.github.io/vue2-perfect-scrollbar/
MIT License
275 stars 43 forks source link

Vue Router ScrollBehavior option #35

Closed lordroseman closed 4 years ago

lordroseman commented 4 years ago

Hi,

How can I make it work with Vue router's scrollBehavior Option?

mercs600 commented 4 years ago

@lordroseman have a look at this example -> https://codesandbox.io/s/vue-routing-example-jbokc?fontsize=14&hidenavigation=1&theme=dark

Just watch on $route and set scrollTop of scroll container on 0.

If you need to setup global scrollbehavior by router options you have to query selector with scroll container and setup scroll top to 0. Because there is not easy access to scroll container.

lordroseman commented 4 years ago

Thats a good option too, this is what i did,

If you need to setup global scrollbehavior by router options you have to query selector with scroll container and setup scroll top to 0. Because there is not easy access to scroll container.

_router.afterEach((to, from) => {
    const container = document.querySelector(".wrapper .ps");
    container.scrollTop = 0;
});