javascript - Is there any good way for vue to return to the previous route and keep the position unchanged?
滿天的星座
滿天的星座 2017-05-16 13:43:04
0
1
581

Pull up to refresh to achieve paging. If there are many pages, click on a page in the list to go to details, and then return to the previous page from the details. The position cannot be changed, and the code will not be refreshed. Forget about using scrollBehavior. I use The one is hash mode. I have done something similar. I hope you can give me some advice.

滿天的星座
滿天的星座

reply all(1)
習慣沉默
beforeRouteLeave(to, from, next){
  let position = window.scrollY()
  this.$store.commit('SAVE_POSITION', position) //离开路由时把位置存起来
}

Get the value in the page

mounted () {
  this.$nextTick(function(){
    let position = this.$store.state.position //返回页面取出来
    window.scroll(0, position)
  }) 
}
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template