Template
1
0
mirror of https://github.com/un-pany/v3-admin-vite.git synced 2025-04-21 11:29:20 +08:00

perf: 优化 router-view 绑定 key 的方式

This commit is contained in:
pany 2023-08-24 16:24:59 +08:00
parent 28edb3775a
commit 59a412ace3

View File

@ -1,24 +1,16 @@
<script lang="ts" setup>
import { computed } from "vue"
import { useRoute } from "vue-router"
import { useTagsViewStore } from "@/store/modules/tags-view"
const route = useRoute()
const tagsViewStore = useTagsViewStore()
const key = computed(() => {
// route.path route.fullPath path
return route.path
})
</script>
<template>
<section class="app-main">
<div class="app-scrollbar">
<router-view v-slot="{ Component }">
<!-- key 采用 route.path route.fullPath 有着不同的效果大多数时候 path 更通用 -->
<router-view v-slot="{ Component, route }">
<transition name="el-fade-in" mode="out-in">
<keep-alive :include="tagsViewStore.cachedViews">
<component :is="Component" :key="key" />
<component :is="Component" :key="route.path" />
</keep-alive>
</transition>
</router-view>