vue滚动后,后退回到记录位置
路由配置文件里const router = new VueRouter({mode: 'history',[{path: '/',name: 'home',component: home,meta: {title: 'home',keepAlive: true
·
路由配置文件里
const router = new VueRouter({
mode: 'history',
[
{
path: '/',
name: 'home',
component: home,
meta: {
title: 'home',
keepAlive: true
}
}
],
scrollBehavior (to, from, savedPosition) {
if (savedPosition) {
return savedPosition
} else {
if (from.meta.keepAlive) {
from.meta.savedPosition = document.body.scrollTop
}
return { x: 0, y: to.meta.savedPosition || 0 }
}
}
})
在组件中
<keep-alive >
<router-view v-if="$route.meta.keepAlive"></router-view>
</keep-alive>
<router-view v-if="!$route.meta.keepAlive"></router-view>
更多推荐
已为社区贡献25条内容
所有评论(0)