首页 > 解决方案 > 如何在 vue3.x 中创建类似 KeepAlive 的组件

问题描述

版本

3.1.2

转载链接

https://github.com/hezhongfeng/vue-page-stack/tree/next

重现步骤

我不喜欢 Vue 的 KeepAlive 缓存策略,所以我想创建一个类似 KeepAlive 的组件。但是当我将我的组件与 一起使用时transition,出现了错误Uncaught TypeError: Cannot read property '_' of null。此错误是由packages/runtime-core/src/componentSlots.tsinitSlots 创建的。我不知道如何解决它。

const KKeepAliveImpl: ComponentOptions = {
  name: `KKeepAlive`,
  __isKeepAlive: true,

  setup(props, { slots }: SetupContext) {
    return () => {};
  },
};

const KKeepAlive = KKeepAliveImpl as any as {
  __isKeepAlive: true;
  new (): {
    $props: VNodeProps;
  };
};

有人有想法吗?

标签: vue.jsvuejs3

解决方案


推荐阅读