实现从B页面跳转到A页面,A页面需要缓存
我的代码:
A页面路由配置:
{ path: 'tea_audit',
meta: {
keepAlive: true,
},
component: _import('teacher/tea_audit')
}
B页面路由配置:
{
path: 'infoDetail/:id/:type',
meta: {
keepAlive: true,
},
hidden: true,
component: _import('teacher/tea_infoDetail')
}
router-view:
<template>
<section class="app-main">
<transition name="fade" mode="out-in">
<keep-alive v-if="$route.meta.keepAlive">
<router-view :key="key"></router-view>
</keep-alive>
<router-view v-if="!$route.meta.keepAlive" :key="key">
</router-view>
</transition>
</section>
</template>
但是从B页面使用router-link返回A页面时,A页面执行了created和mounted方法
<router-link :to="{ name: backPageName, params: {activeName: backTabName}}">返回</router-link>
为什么呀,A到B的时候确实是执行created-> mounted-> activated,退出时触发deactivated的,为什么回来A执行了created-> mounted-> activated,求解
- 3
新手上路,请多包涵A页面,于B页面如果不在一个router-view组件中将再次触发mounted钩子。还有就是v-if的keep-alive,两个组件的缓存状态不一致时,也会造成重新触发mounted钩子。