Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.0k views
in Technique[技术] by (71.8m points)

vue 用了keepAlive 我各个路由滚动条互相影响

举例说明:
两个页面(首页、我的订单) 两个页面通过底部tabbar切换
我在首页往下滑动800(scrollTop),切换到订单页、订单页滚动条也在800,订单页回到顶部,首页也会回到顶部

这是不是共用了滚动条啊?而且keepAlive为false的页面,也会影响滚动条,就像是这整个路由模块都是一个滚动条一样

求解..好迷惑。


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

https://router.vuejs.org/zh/guide/advanced/scroll-behavior.html#异步滚动

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...