fix: 修复懒加载组件keep-alive不生效问题

This commit is contained in:
liumangmang
2026-03-30 16:41:16 +08:00
parent e895124831
commit ba1acdc2dd
2 changed files with 12 additions and 8 deletions

View File

@@ -190,10 +190,13 @@ function handleSftpTabClose(tabId: string, connectionId: number, event: Event) {
<div v-if="keepTerminalWorkspaceMounted" v-show="showTerminalWorkspace" class="h-full"> <div v-if="keepTerminalWorkspaceMounted" v-show="showTerminalWorkspace" class="h-full">
<TerminalWorkspaceView :visible="showTerminalWorkspace" /> <TerminalWorkspaceView :visible="showTerminalWorkspace" />
</div> </div>
<RouterView v-slot="{ Component }"> <RouterView v-slot="{ Component, route }">
<keep-alive :include="['SftpView']" :max="10"> <template v-if="!showTerminalWorkspace">
<component :is="Component" v-if="!showTerminalWorkspace" :key="$route.fullPath" /> <keep-alive :max="10" v-if="route.meta.keepAlive">
</keep-alive> <component :is="Component" :key="route.fullPath" />
</keep-alive>
<component :is="Component" :key="route.fullPath" v-else />
</template>
</RouterView> </RouterView>
</main> </main>
</div> </div>

View File

@@ -39,10 +39,11 @@ const routes: RouteRecordRaw[] = [
name: 'Terminal', name: 'Terminal',
component: () => import('../views/TerminalView.vue'), component: () => import('../views/TerminalView.vue'),
}, },
{ {
path: 'sftp/:id', path: 'sftp/:id',
name: 'Sftp', name: 'Sftp',
component: () => import('../views/SftpView.vue'), component: () => import('../views/SftpView.vue'),
meta: { keepAlive: true },
}, },
], ],
}, },