相信在利用路由跳转时都遇到过,打开的新页面是页面的底部而不是顶部。
我们可以用过修改解决这个问题。

export default new Router({
  routes: [{
    path: '/',
    name: 'Index',
    component: Index,
    meta: {
      keepalive: false,
    }
  }],
  scrollBehavior (to, from, savedPosition) {
    return { x: 0, y: 0 }
  }
})

可以在index.js中加入scrollBehavior方法来更改打开新页面的位置

Logo

Vue社区为您提供最前沿的新闻资讯和知识内容

更多推荐