路由跳转,页面位置不在顶部

在对应路由的页面,添加一个scrollBehavior方法

const router = new VueRouter({ 
  routes,
  scrollBehavior(to, from, saveTop) { 
    if (saveTop) { 
      return saveTop; 
    } else { 
      return { x: 0, y: 0 } 
      } 
    },
  })

 

posted @ 2021-09-08 13:45  #小小佳  阅读(185)  评论(0编辑  收藏  举报