Blame view

ant-design-vue-jeecg/src/components/layouts/RouteView.vue 1.67 KB
肖超群 authored
1
2
<template>
  <div class="main">
肖超群 authored
3
4
5
6
    <keep-alive :include="includedComponents">
      <router-view v-if="keepAlive"/>
    </keep-alive>
    <router-view v-if="!keepAlive"/>
肖超群 authored
7
8
9
10
  </div>
</template>

<script>
肖超群 authored
11
12
import Vue from 'vue'
import {CACHE_INCLUDED_ROUTES} from "@/store/mutation-types"
肖超群 authored
13
肖超群 authored
14
15
16
17
18
export default {
  name: "RouteView",
  computed: {
    //update-begin--Author:scott  Date:20201015 for:路由缓存问题,关闭了tab页时再打开就不刷新 #842
    includedComponents() {
19
20
      console.log('路由缓存:' + this.$route.meta.title, this.$route.meta.keepAlive, this.$route.meta.componentName)
肖超群 authored
21
22
      const includedRouters = Vue.ls.get(CACHE_INCLUDED_ROUTES)
      console.log("includedRouters:" + includedRouters)
肖超群 authored
23
肖超群 authored
24
25
26
27
28
29
30
31
32
33
      //如果是缓存路由,则加入到 cache_included_routes
      if (this.$route.meta.keepAlive && this.$route.meta.componentName) {
        let cacheRouterArray = Vue.ls.get(CACHE_INCLUDED_ROUTES) || []
        if (!cacheRouterArray.includes(this.$route.meta.componentName)) {
          cacheRouterArray.push(this.$route.meta.componentName)
          // cacheRouterArray.push("OnlCgformHeadList")
          console.log("Vue ls set componentName :" + this.$route.meta.componentName)
          Vue.ls.set(CACHE_INCLUDED_ROUTES, cacheRouterArray)
          console.log("Vue ls includedRouterArrays :" + Vue.ls.get(CACHE_INCLUDED_ROUTES))
          return cacheRouterArray;
肖超群 authored
34
35
        }
      }
肖超群 authored
36
      return includedRouters;
肖超群 authored
37
    },
肖超群 authored
38
39
    //update-end--Author:scott  Date:20201015 for:路由缓存问题,关闭了tab页时再打开就不刷新 #842
    keepAlive() {
40
      // this.$route.meta.keepAlive = true
肖超群 authored
41
42
43
44
      return this.$route.meta.keepAlive
    }
  },
}
肖超群 authored
45
</script>