why VueJs router savedPosition for scrollBehavior returns first undefined and next {x:0,y:0}

走远了吗. 提交于 2019-12-11 05:18:32

问题


I use vue-router 2.5.3 and have two pages: first for long list (loaded via ajax) and second for details.

When I scroll down on list page and next navigate using clicking back the browser button the browser always scrolls to the top. The value of savedPosition is for the first time undefined and for next attempts Object {x: 0, y: 0}

<div class="main-content">
  <router-view ></router-view>
</div>

scrollBehavior(to, from, savedPosition) {
    console.info(savedPosition) // first attemp undefined and next  always {x: 0, y: 0} regardless previous position

    if (savedPosition) {
      return savedPosition
    } else if (to.name == from.name) 
    {
      return
    }
    else {
      return { x: 0, y: 0 }
    }
  },
  mode: 'history',

what is savedPosition and how it is triggered ?

来源:https://stackoverflow.com/questions/44011979/why-vuejs-router-savedposition-for-scrollbehavior-returns-first-undefined-and-ne

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!