vue页面路由跳转离开时保存滚动条位置,进入该页面是获取位置
beforeRouteLeave (to, from, next) {const position = document.documentElement.scrollTopsessionStorage.setItem('scrollTop', JSON.stringify(position))next()},// // 进入该页面时,用之前保存的滚动位置赋值beforeRouteEnter (to, from, next) {// if(to.path===window.location.href){// this.$router.push('/list')// }const val = JSON.parse(window.sessionStorage.getItem('scrollTop'))next(val => {document.body.scrollTop = val})},
KeepAlive包裹组件

路由配置keepalive为true

以上保存滚动条的位置
VUE单页面actived生命周期里重新调用获取list的方法

这样数据刷新了,页面保存了














