forked from UzTech/Vue3-typescript-demo
init
This commit is contained in:
27
src/App.vue
Normal file
27
src/App.vue
Normal file
@@ -0,0 +1,27 @@
|
||||
<template>
|
||||
<router-view v-slot="{ Component }">
|
||||
<keep-alive :include="includeList">
|
||||
<component :is="Component"></component>
|
||||
</keep-alive>
|
||||
</router-view>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { ref, watch } from 'vue'
|
||||
import { RouteLocationNormalizedLoaded, useRoute } from 'vue-router'
|
||||
|
||||
const includeList = ref<string[]>([])
|
||||
const route = useRoute()
|
||||
|
||||
watch(route, (to: RouteLocationNormalizedLoaded) => {
|
||||
if (to.meta?.keepAlive && includeList.value.indexOf(to.name as string) === -1) {
|
||||
includeList.value.push(to.name as string)
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
<style lang="less">
|
||||
body {
|
||||
background: #f7f8fa;
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user