vue2用法
<keep-alive :include="keepAliveNames"><router-view></router-view>
</keep-alive>
<script>//include代表缓存name是FleetList的组件this.keepAliveNames = 'FleetList'
</script>
vue3用法
<router-view v-slot="{ Component }"><keep-alive :include="keepAliveNames"><component :is="Component"></component></keep-alive>
</router-view>
<script setup>//include代表缓存name是FleetList的组件const keepAliveNames = ref('FleetList')
</script>
不要问Component 是什么,这么写就对了。
ps:因为我也不知道Component 是什么,折腾了好久才明白。不要问,问就是:is=“Component"的跟v-slot=”{ Component }"一样就对了