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里面把这三个路由写出来

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

这样就可以了

相关推荐
随风,奔跑1 小时前
Redis
数据库·redis·缓存
TlYf NTLE2 小时前
redis分页查询
数据库·redis·缓存
大萌神Nagato3 小时前
力扣HOT100 Q146LRU缓存
算法·leetcode·缓存
鬼蛟3 小时前
Redis
数据库·redis·缓存
8Qi84 小时前
Redis哨兵模式(Sentinel)深度解析
java·数据库·redis·分布式·缓存·sentinel
CDN3606 小时前
CDN 缓存命中率低如何提升?忽略参数与规则设置教程
运维·缓存
M--Y6 小时前
初识Redis
数据库·redis·缓存
皙然7 小时前
Redis核心理论:数据删除与淘汰策略详解(从原理到实战)
数据库·redis·缓存
爱丽_8 小时前
MyBatis 性能优化:批处理、分页、缓存与慢 SQL 定位
缓存·性能优化·mybatis
磊 子8 小时前
Redis详解
linux·数据库·redis·缓存