vue3 的 router-view keep-alive写法:
<router-view v-slot="{ Component, route }">
<keep-alive :include="includeList">
<component
:is="Component"
:key="route.name"
v-if="includeList.includes(route.name)"
/>
</keep-alive>
<component
:is="Component"
:key="route.name"
v-if="(!includeList.includes(route.name) && !route.meta.keepAlive)"
/>
</router-view>
- 首先确保
include
传的值为官方文档中的三种形式:keep-alive - 确保
<component>
对应的组件里面定义了name
(<script setup>
语法糖无法定义name
,需改成非语法糖形式,自己取舍吧)