浏览代码

启动页面缓存机制,以观后效 - 简版缓存,有待改进

hare8999@163.com 3 年之前
父节点
当前提交
93440db3ba
共有 2 个文件被更改,包括 14 次插入3 次删除
  1. 13 2
      src/layout/components/AppMain.vue
  2. 1 1
      src/views/elective/generation/index.vue

+ 13 - 2
src/layout/components/AppMain.vue

@@ -1,7 +1,7 @@
 <template>
   <section class="app-main">
     <transition name="fade-transform" mode="out-in">
-      <keep-alive :include="cachedViews">
+      <keep-alive :max="maxCacheCount">
         <router-view :key="key"/>
       </keep-alive>
     </transition>
@@ -11,12 +11,23 @@
 <script>
 export default {
   name: 'AppMain',
+  data() {
+    return {
+      maxCacheCount: 5 // 最多缓存尺寸 // 5.11 hht 加个尺寸控制,防止key值缓存过多
+    }
+  },
   computed: {
     cachedViews() {
       return this.$store.state.tagsView.cachedViews
     },
     key() {
-      return this.$route.path
+      // TODO: 5.11 hht keep-alive的include/exclude结合router-view好像不能正常工作, 目前没有弄清原因
+      // NOTE: 先通过key的途径解决缓存刷新的问题
+      const meta = this.$route.meta
+      const useCache = meta && meta.hasOwnProperty('noCache') && meta.noCache === false
+      const fullPath = this.$route.fullPath
+      const cacheControlArgs = useCache ? '' : ('_' + new Date().getTime())
+      return fullPath + cacheControlArgs
     }
   }
 }

+ 1 - 1
src/views/elective/generation/index.vue

@@ -28,7 +28,7 @@ import MxGroupTranslateMixin from '@/components/Cache/modules/mx-select-translat
 
 export default {
   mixins: [MxGroupTranslateMixin],
-  name: 'generation-index',
+  name: 'ElectiveGenerationIndex',
   components: { ElectiveGenerationMaster, ElectiveGenerationSteps, MxCondition },
   data() {
     return {