官方文档说了关于路由里面的一个属性
noCache: true时不会缓存
说的是很容易理解 但是我始终没有效果 所以就按照传统写法重写了一遍
meta: { title: 'xx', activeMenu: '/customer', keepAlive: true }
在路由meta里面加了个keepAlive: true
然后在App.vue中添加keep-alive标签
<div id="app">
{{$route.meta.keepAlive}}
<keep-alive>
<router-view v-if="$route.meta.keepAlive" />
</keep-alive>
<router-view v-if="$route.meta.keepAlive !== true" />
</div>
然后到这里之后 还是不好使 百度了很多资料 找到了个有趣的文件
我们到AppMain.vue中 位置在layout里面
<section class="app-main">
<transition name="fade-transform" mode="out-in">
<keep-alive v-if="cachedViews || alive === true">
<router-view :key="key" />
</keep-alive>
</transition>
</section>
稍微修改了一下
在computed加了个alive判断这个页面是否需要缓存
alive() {
return this.$route.meta.keepAlive
},