index.ts 411 B

12345678910111213141516
  1. import { useRouter } from 'vue-router';
  2. /**
  3. * vue路由跳转之后页面停留在上一个浏览页面位置不会回到顶部
  4. */
  5. export function handleRouterToTop() {
  6. const router = useRouter();
  7. router.beforeEach((to, from, next) => {
  8. // chrome
  9. document.body.scrollTop = 0;
  10. // firefox
  11. document.documentElement.scrollTop = 0;
  12. next();
  13. });
  14. return {};
  15. }