keep-alive的生命周期
activated: 页面第一次进入的时候,钩子触发的顺序是created->mounted->activated
deactivated: 页面退出的时候会触发deactivated,当再次前进或者后退的时候只触发activated
<keep-alive> <router-view v-if="$route.meta.keepAlive"></router-view> </keep-alive> <router-view v-if="!$route.meta.keepAlive"></router-view>
router配置
routes: [
{
path: '/',
name: 'index',
component: index,
meta: {
requiresAuth: true,
keepAlive: true
}
}
]vue keep-alive配置