keep alive component expose inner cache & keys #7702
jiangshengdev
started this conversation in
Ideas
Replies: 1 comment 1 reply
-
Subject: [PATCH] feat: keep alive expose
---
Index: packages/runtime-core/src/components/KeepAlive.ts
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/packages/runtime-core/src/components/KeepAlive.ts b/packages/runtime-core/src/components/KeepAlive.ts
--- a/packages/runtime-core/src/components/KeepAlive.ts (revision a0e7dc334356e9e6ffaa547d29e55b34b9b8a04d)
+++ b/packages/runtime-core/src/components/KeepAlive.ts (date 1676282064399)
@@ -87,7 +87,7 @@
max: [String, Number]
},
- setup(props: KeepAliveProps, { slots }: SetupContext) {
+ setup(props: KeepAliveProps, { slots, expose }: SetupContext) {
const instance = getCurrentInstance()!
// KeepAlive communicates with the instantiated renderer via the
// ctx where the renderer passes in its internals,
@@ -243,6 +243,13 @@
})
})
+ expose({
+ cache,
+ keys,
+ pruneCache,
+ pruneCacheEntry
+ })
+
return () => {
pendingCacheKey = null
|
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Vue2 supports simple creation of my own keep alive component
but Vue3 build-in Comonent KeepAlive has Interact with apiLifecycle
This makes it difficult to manage the internal cache manually, for example:
#6219
Expose the internal variables of keep alive, which can solve this problem, but whether it is appropriate still needs to be discussed
https://github.com/vuejs/core/blob/a0e7dc334356e9e6ffaa547d29e55b34b9b8a04d/packages/runtime-core/src/components/KeepAlive.ts
PS:
I currently use patch-package to modify the source code in my own project
https://www.npmjs.com/package/patch-package
Beta Was this translation helpful? Give feedback.
All reactions