实现从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,求解
- 2
新手上路,请多包涵应该是这个写法吧。v-if加到<router-view>上,而不是<keep-alive>上。要不然,keep-alive就被干掉了,谁负责缓存嘞。