Skip to content

Commit c1ac56b

Browse files
committed
页面后退,状态复原
1 parent 621843a commit c1ac56b

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

src/App.vue

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
<template>
22
<div>
33
<transition name="router-fade" mode="out-in">
4-
<router-view></router-view>
4+
<keep-alive>
5+
<router-view v-if="$route.meta.keepAlive"></router-view>
6+
</keep-alive>
57
</transition>
8+
<transition name="router-fade" mode="out-in">
9+
<router-view v-if="!$route.meta.keepAlive"></router-view>
10+
</transition>
611
</div>
712
</template>
813

src/main.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,17 @@ Vue.use(VueRouter)
1616
const router = new VueRouter({
1717
routes,
1818
mode: routerMode,
19-
strict: process.env.NODE_ENV !== 'production'
19+
strict: process.env.NODE_ENV !== 'production',
20+
scrollBehavior (to, from, savedPosition) {
21+
if (savedPosition) {
22+
return savedPosition
23+
} else {
24+
if (from.meta.keepAlive) {
25+
from.meta.savedPosition = document.body.scrollTop;
26+
}
27+
return { x: 0, y: to.meta.savedPosition ||0}
28+
}
29+
}
2030
})
2131

2232

src/router/router.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ export default [{
7272
{
7373
path: '/msite',
7474
component: msite,
75+
meta: { keepAlive: true },
7576
},
7677
//特色商铺列表页
7778
{

0 commit comments

Comments
 (0)