-
Notifications
You must be signed in to change notification settings - Fork 34
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
🐛 [Bug]:keep-alive时不起作用,无法实现路由缓存 #126
Comments
Title: 🐛 [Bug]: does not work when keep-alive, route caching cannot be implemented |
感谢您的反馈,请提供一下复现demo,以便更快地排查此问题 |
Thank you for your feedback. Please provide a reproduction demo to troubleshoot this issue faster. |
demo 源代码 |
After analysis, the reason is that the keep/index.vue layer component is switched as a whole when switching routes, so the keep-alive inside it will not have any effect**. |
【方案一】不依赖路由, 仅在页面级进行组件切换,验证缓存 <keep-alive>
<component :is="curr.value" />
</keep-alive> 脚本: import { ref ,reactive ,markRaw} from 'vue'
import { RadioGroup as TinyRadioGroup, RadioButton as TinyRadioButton } from '@opentiny/vue'
import AVue from "./A/index.vue"
import BVue from "./B/index.vue"
const activeName = ref('A')
const curr= reactive({
value: markRaw(AVue)
})
const onChange = (event: any) => {
if(event==='A'){
curr.value=markRaw(AVue)
}else{
curr.value=markRaw(BVue)
}
} |
【方案2】 使用路由缓存, 但是路由的keey-alive要在上级路由中添加 <router-view v-slot="{ Component, route }">
<keep-alive>
<component :is="Component" :key="route.fullPath" />
</keep-alive>
</router-view> 然后index.vue不需要变化。 结论: 想缓存keep中的路由页面,必须在keep的父级的router-view进行缓存。 |
[Option 2] Use route cache, but the keey-alive of the route must be added to the upper-level route. <router-view v-slot="{ Component, route }">
<keep-alive>
<component :is="Component" :key="route.fullPath" />
</keep-alive>
</router-view> Then index.vue does not need to change. Conclusion: If you want to cache the routing page in keep, you must cache it in the router-view of the parent of keep. |
Version
tiny v1.1.0
node-version
v16.20.2
Link to minimal reproduction
No response
Step to reproduce
为了实现Tabs切换功能,我要用到路由缓存keep-alive,但一直不起作用,试了很多种方法还是一样,然后新建项目试了一下还是keepalive不生效,没法实现路由缓存。
What is expected
No response
What is actually happening
No response
Any additional comments (optional)
No response
The text was updated successfully, but these errors were encountered: