当前位置:   article > 正文

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

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

方式1:采用原有的

  1. <template>
  2. <section class="app-main">
  3. <transition name="fade-transform" mode="out-in">
  4. <keep-alive :include="cachedViews">
  5. <router-view :key="key" />
  6. </keep-alive>
  7. </transition>
  8. <!-- :include='/componentA|componentB' 正则写法 -->
  9. <!-- :include="['componentA','componentB']" 数组写法 -->
  10. <!-- <keep-alive :include="keepAliveComponents">
  11. <router-view />
  12. </keep-alive> -->
  13. </section>
  14. </template>

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

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

方式2:采用观察者

  1. watch: {
  2. $route: {
  3. // 监听路由变化
  4. handler(to, from) {
  5. if (to.meta.keepAlive) {
  6. // 不重复增加
  7. if (!this.keepAliveComponents.includes(to.name)) {
  8. this.keepAliveComponents.push(to.name)
  9. }
  10. } else {
  11. //
  12. }
  13. },
  14. immediate: true // 开启立即监听
  15. }
  16. }
  17. }

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

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/知新_RL/article/detail/489234
推荐阅读
相关标签
  

闽ICP备14008679号