返回博客

Vue3 中使用 keep-alive 组件报错:TypeError: parentComponent.ctx.deactivate is not a function 的解决方法

Vue3 使用 keep-alive 组件时,切换页面报错 TypeError: parentComponent.ctx.deactivate is not a function。文章提供了解决方案:在 keep-alive 和 component 上设置 key 属性进行排序,并附带相关参考文章链接。

Mt.r
|

vue3 在使用 keep-alive 出现切换页面报错

多看底层源码 https://xie.infoq.cn/article/987b17e0c8b59198785025162

解决

keep-alivecomponent 上设置 key 进行排序

<router-view v-slot="{ Component, route }">
  <keep-alive>
    <component :is="Component" :key="route.name" v-if="route.meta.keepAlive" />
  </keep-alive>
  <component :is="Component" :key="route.name" v-if="!route.meta.keepAlive" />
</router-view>

其他参考文章