配置路由
export default new Router({
routes: [
{
path: '/hello',
name: 'HelloWorld',
component: HelloWorld,
meta: {
keepAlive: true // 需要缓存
}
},
{
path: '/hello2',
name: 'HelloWorld2',
component: HelloWorld2,
meta: {
keepAlive: false // 不需要缓存
}
}
],
mode: 'history',
scrollBehavior (to, from, savedPosition) {
if (savedPosition) {
return savedPosition
} else {
return { x: 0, y: 0 }
}
}
配置App.vue文件种的<router-view/>
<keep-alive>
<router-view v-if="$route.meta.keepAlive"></router-view>
</keep-alive>
<router-view v-if="!$route.meta.keepAlive"></router-view>
使用this.$router.back()返回
当用户在详情页点击返回的按钮时,我们把按钮的返回事件 this.router.back(), 必须用这个才能生效
网友评论