javascript - vue有什么好的办法返回上一个路由保持位置不变。
本文介绍了javascript - vue有什么好的办法返回上一个路由保持位置不变。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问 题
上拉刷新来实现分页,当有很多页的话,点击列表某一页去详细,然后从详情返回上一页,位置不能变,而且代码不会刷新,使用scrollBehavior还是算了,我用的是hash模式,有做过类似,希望能给点意见。
解决方案
beforeRouteLeave(to, from, next){
let position = window.scrollY()
this.$store.commit('SAVE_POSITION', position) //离开路由时把位置存起来
}
在页面中取值
mounted () {
this.$nextTick(function(){
let position = this.$store.state.position //返回页面取出来
window.scroll(0, position)
})
}
这篇关于javascript - vue有什么好的办法返回上一个路由保持位置不变。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文