-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(KeepAlive): support matchBy + allow custom caching strategy #4339
base: main
Are you sure you want to change the base?
feat(KeepAlive): support matchBy + allow custom caching strategy #4339
Conversation
Looking forward to this feature. |
Looking forward to this feature. |
大概在之后哪个版本可以正式用上他呢 |
Looking forward to this feature. |
Looking forward to this feature |
Looking forward... |
This keep-alive custom purge feature is so important for multi tab pages. And it have been discussed many time since Vue2. I don't why this is not fixed yet now. Vue3 team should really think about it. |
As @tony-gm says, this feature is essential for multi-tab pages where the tabs are instances of the same component and the key is being used to differentiate them. For me it is enough that the include/exclude can match on key as well as name, as the custom caching part is what I would consider advanced functionality. So can the key matching be implemented by itself as this is a much simpler (and presumably less risky?) change. Hard to see why it has not already been done when it seems so straightforward. |
Here is a temporary solution I can share, hope can help somebody who also work on sort of "multi tab page" project.
It's work , now we can remove any cache by a key;
Base on this, the FINALLY, there is only one way I can do is to modify the vue distributed file to remove the DEV predication, just like below
Now
|
Thanks @tony-gm, I had already encountered the solution to use the cache directly and also ran into the production mode problem but your subsequent fix for this has solved this for me too. It will keep us going until Vue can add the correct functionality to keep-alive |
Since the keep-alive keep bother me a long time. I have a proposal
export interface KeepAliveCache {
include: Ref<MatchPattern | undefined>
exclude: Ref<MatchPattern | undefined>
max: Ref<number | string | undefined>
cache: Map<string, VNode>
remove: (key: string) => void
clear: () => void
}
Here is a full example <template>
<button @click="onCloseTab">Close Current Tab</button>
<button @click="onCloseAllTabs">Close All Tabs</button>
<router-view v-slot="{ Component, route }">
<keep-alive :cache="pageCache">
<component :is="Component" :key="route.fullPath" />
</keep-alive>
</router-view>
</template>
<script lang="ts">
import { defineComponent, createKeepAliveCache, ref } from 'vue'
export default defineComponent({
name: 'App',
setup() {
const currentPath = ref('')
const pageCache = createKeepAliveCache()
pageCache.include.value = ['Component1']
function onCloseTab() {
pageCache.remove(currentPath.value)
}
function onCloseAllTabs() {
pageCache.clear()
}
return {
pageCache,
onCloseTab,
onCloseAllTabs
}
}
})
</script> I document this in a RFC , more detail please check RFC Link And I also did a prototype implement base on this RFC, currently it's work. Implement Link Hope vuejs team can enhance keep-alive component like this. |
we really need the feature, more and more apps with multi tabs pop up |
Need this feature. |
不要使用 |
原因找到了,我用了pinia存储了wrapperMap,所以组件变成了响应式的。 |
Looking forward to this feature |
keep-alive这个特性可以使用了吗? |
This scheme can be tried while waiting for the merger, although it is extremely harmful. |
这个问题可真是如鲠在喉,对移动端很多网站来说这是重大缺陷,如今很多都是滚动加载的页面,谁能接受他回不去,网站都写完了才发现这个问题。。而且nuxt3的NuxtPage对keepalive包含排除还有BUG,还不能用原生的路由替换,默契配合超级加倍 |
这个特性能用了吗 |
这个特性能用了吗? |
我试着完成了一个不完善的页面堆栈管理,目前唯一的缺点是不能使用transition. |
#5105 |
找到一个对第三库源代码打补丁的方法: npm/yarn:patch package。 我用的是 pnpm,他内置了一个 patch 命令 ( pnpm patch ),下面说一下具体操作: pnpm patch @vue/[email protected] 然后 pnpm 会打印出库文件的临时源代码目录,进入修改 ./dist 目录的 3 个 js 文件:
最后运行上述 pnpm 语句给出的 |
see |
need this feature |
1 similar comment
need this feature |
+1 |
1 similar comment
+1 |
需要这个功能,实在是很困扰 |
需要这个功能 |
unplanned? |
Really need this feature |
这个特性能用了吗? |
想多了 |
我真服了,我直接patch源代码得了 |
我用的都是楼上的一个大牛的方案做的,等这个特性要死人的 |
This is a copy of the old PR #3414, for some reasons, I had to reopen a new one.
RFC vuejs/rfcs#284