vue3 router-view keep-alive include 不生效问题解决

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>
  1. 首先确保include传的值为官方文档中的三种形式:keep-alive
  2. 确保<component>对应的组件里面定义了name(<script setup>语法糖无法定义name,需改成非语法糖形式,自己取舍吧)
posted @ 2021-11-17 14:28  豌里个豆  阅读(2849)  评论(0编辑  收藏  举报