img

vue 解决跳转新页面时无法回到顶部的问题

2020-10-07 0条评论 2.7k次阅读 JavaScript


最近写一个项目当页面跳到新的页面时滚动条总是在当前位置

3.gif

然后在router.js里面加了

const createRouter = () => new Router({
    mode: 'history',
    scrollBehavior: () => ({y: 0,x: 0}),
    routes: constantRoutes
});

scrollBehavior: () => ({y: 0,x: 0}),还是没有用

结果打开审查元素发现是因为给body加了overflow: auto;

html, body {
  min-height: 100%;
  padding: 0;
  margin: 0;
  //overflow: auto;
  min-width: 1210px;
}

完美解决!

💬 COMMENT


🦄 支持markdown语法

👋友