forked from UzTech/Vue3-typescript-demo
58 lines
1.0 KiB
Vue
58 lines
1.0 KiB
Vue
<template>
|
|
<router-view v-slot="{ Component }">
|
|
<keep-alive :include="includeList">
|
|
<div id="layout">
|
|
<Header/>
|
|
<component :is="Component"></component>
|
|
<Footer/>
|
|
</div>
|
|
</keep-alive>
|
|
</router-view>
|
|
</template>
|
|
|
|
<script lang="ts" setup>
|
|
import { Footer, Header } from '@/components'
|
|
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">
|
|
* {
|
|
padding: 0;
|
|
margin: 0;
|
|
box-sizing: border-box;
|
|
}
|
|
|
|
body {
|
|
font-size: 14px;
|
|
background: #FAFAFA;
|
|
}
|
|
|
|
#layout {
|
|
.container {
|
|
width: 1200px;
|
|
margin: 0 auto;
|
|
min-height: calc(100vh - 164px);
|
|
}
|
|
}
|
|
|
|
.wrap {
|
|
width: 1200px;
|
|
margin: 0 auto;
|
|
}
|
|
|
|
a {
|
|
text-decoration: none;
|
|
color: #2055ca;
|
|
}
|
|
</style>
|