Browse Source

给页签添加keep-alive缓存

wuhongbo 1 year ago
parent
commit
77b38ce85e

+ 15 - 1
client/src/views/OaSystem/oaLayout/index.vue

@@ -17,15 +17,29 @@
         <TagList />
       </div>
       <div class="layout-content">
-        <router-view />
+        <router-view>
+          <template #default="{ Component, route }">
+            <keep-alive>
+              <component :is="Component" :key="route.fullPath" />
+            </keep-alive>
+          </template>
+        </router-view>
       </div>
     </div>
   </div>
 </template>
 <script setup lang="ts">
+import { useTagsViewStore } from '@/store/modules/tagsView'
 import Header from './header.vue'
 import TagList from './tagList.vue'
 import Menus from './menus.vue'
+
+const tagsViewStore = useTagsViewStore()
+
+const getCaches = computed((): string[] => {
+  return tagsViewStore.getCachedViews
+})
+
 defineOptions({ name: 'Layout' })
 
 /** 初始化 **/

+ 1 - 1
client/src/views/OaSystem/oaLayout/tagList.vue

@@ -69,7 +69,7 @@
           <li>
             <router-link :to="{ ...item }" exact v-slot="{ navigate }" v-if="index == 0">
               <div class="homeBox" @click="navigate">
-                <div @click="tagsHomeClick(item, index)" class="tagsFlex">
+                <div @click="tagsHomeClick()" class="tagsFlex">
                   <Icon :icon="item.meta.icon || ''" />
                   <p>{{ item.meta.title }}</p>
                 </div>