search

Home  >  Q&A  >  body text

javascript - Is there any good way for vue to return to the previous route and keep the position unchanged?

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.

滿天的星座滿天的星座2757 days ago572

reply all(1)I'll reply

  • 習慣沉默

    習慣沉默2017-05-16 13:45:04

    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)
      }) 
    }

    reply
    0
  • Cancelreply