keep-alive缓存三级及三级以上路由

需求需要缓存这个出入记录,当tab切换时不重新加载,当刷新页面时,或把这个关闭在重新打开时重新加载如图:

(我这里用的是芋道源码的前端框架)

keep-alive

1、include 包含页面组件name的这些组件页面,会被缓存起来

2、exclude 除了这些name以外的页面组件,会被缓存起来

3、没有include或者exclude属性,表示所有的路由组件都会被缓存起来

复制代码
<template>
  <section class="app-main">
    <transition name="fade-transform" mode="out-in">
      <keep-alive :include="cachedViews" exclude="redirect">
        <router-view :key="key" />
      </keep-alive>
    </transition>
  </section>
</template>

<script>
export default {
  name: 'AppMain',
  computed: {
    cachedViews() {
      return this.$store.state.tagsView.cachedViews
    },
    key() {
      return this.$route.path
    }
  }
}
</script>

解决方法

现在router里面的index.js里面把这三个路由写出来

然后在仓库里面手动把二级路由加上

这样就可以了

相关推荐
麦兜*27 分钟前
Redis内存消耗异常飙升?深入排查与Big Key/Hot Key的根治方案
jvm·数据库·spring boot·redis·spring·缓存
成为你的宁宁1 小时前
【Redis 从入门到实战:详细讲解 Redis 安装配置、RDB/AOF 数据持久化方案、一主两从同步部署,深入剖析哨兵模式工作原理与哨兵模式高可用全攻略】
数据库·redis·缓存
ifeng09181 小时前
HarmonyOS网络请求优化实战:智能缓存、批量处理与竞态处理
网络·缓存·harmonyos
5***o5001 小时前
前端构建工具缓存清理,解决依赖问题
前端·缓存
一叶飘零_sweeeet5 小时前
2025 年 Redis 面试天花板
redis·缓存·面试
d***9356 小时前
Redis五种用途
数据库·redis·缓存
stevenzqzq12 小时前
android recyclerview缓存2_四级缓存机制
android·spring boot·缓存
q***d17312 小时前
后端缓存技术学习资源,Redis+Memcached
redis·学习·缓存
麦兜*14 小时前
Redis在Web3中的应用探索:作为链下状态缓存与索引层
java·spring boot·redis·spring cloud·缓存·docker·web3
qwer12321ck761 天前
Maven在本地仓库缓存了失败的下载记录
缓存·maven