上拉刷新來實(shí)現(xiàn)分頁,當(dāng)有很多頁的話,點(diǎn)擊列表某一頁去詳細(xì),然後從詳情返回上一頁,位置不能變,而且代碼不會(huì)刷新,使用scrollBehavior還是算了,我用的是hash模式,有做過類似,希望能給點(diǎn)意見。
beforeRouteLeave(to, from, next){
let position = window.scrollY()
this.$store.commit('SAVE_POSITION', position) //離開路由時(shí)把位置存起來
}
在頁中取值
mounted () {
this.$nextTick(function(){
let position = this.$store.state.position //返回頁面取出來
window.scroll(0, position)
})
}