Vue-admin-template关于TagView缓存问题

方式1:采用原有的

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

    <!-- :include='/componentA|componentB' 正则写法 -->
    <!-- :include="['componentA','componentB']" 数组写法 -->
    <!-- <keep-alive :include="keepAliveComponents">
      <router-view />
    </keep-alive> -->
  </section>
</template>

后端通过 :meta中noCache字段 来决定是否执行缓存。

注意:路由Name和组件中Name要相同。

方式2:采用观察者

  watch: {
    $route: {
      // 监听路由变化
      handler(to, from) {
        if (to.meta.keepAlive) {
          // 不重复增加
          if (!this.keepAliveComponents.includes(to.name)) {
            this.keepAliveComponents.push(to.name)
          }
        } else {
          //
        }
      },
      immediate: true // 开启立即监听
    }
  }
}

关键点在于 keepAliveComponents 需要处理TagView全局关闭和部分关闭问题。

相关推荐

  1. Vue-admin-template关于TagView缓存问题

    2024-04-22 12:28:03       32 阅读
  2. Vue3-admin-template的表格合计计算

    2024-04-22 12:28:03       60 阅读
  3. 关于缓存的一些问题

    2024-04-22 12:28:03       39 阅读
  4. Template -- Vue3

    2024-04-22 12:28:03       52 阅读
  5. Template -- Vue2

    2024-04-22 12:28:03       54 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-04-22 12:28:03       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-04-22 12:28:03       101 阅读
  3. 在Django里面运行非项目文件

    2024-04-22 12:28:03       82 阅读
  4. Python语言-面向对象

    2024-04-22 12:28:03       91 阅读

热门阅读

  1. uniapp如何适配ipad

    2024-04-22 12:28:03       34 阅读
  2. 用虚拟机搭建sqlmap靶机环境

    2024-04-22 12:28:03       33 阅读
  3. 结构体与共用体2

    2024-04-22 12:28:03       26 阅读
  4. 大数据:【学习笔记系列】 Flink 学习路线

    2024-04-22 12:28:03       31 阅读
  5. HOW - 实现加权随机函数

    2024-04-22 12:28:03       31 阅读
  6. SiteMesh介绍

    2024-04-22 12:28:03       26 阅读
  7. 初始jQuery

    2024-04-22 12:28:03       33 阅读
  8. 二分答案算法

    2024-04-22 12:28:03       24 阅读
  9. 图片懒加载的三种方式

    2024-04-22 12:28:03       32 阅读
  10. QT c++ 将浮点数数组转换成 QByteArray

    2024-04-22 12:28:03       41 阅读
  11. 算法训练营day14

    2024-04-22 12:28:03       36 阅读
  12. css常见动画

    2024-04-22 12:28:03       26 阅读
  13. 开发语言漫谈-Object C

    2024-04-22 12:28:03       33 阅读
  14. [leetcode] 946. 验证栈序列

    2024-04-22 12:28:03       37 阅读