Closed condorheroblog closed 3 weeks ago
这些因为考虑到,很多场景会误用的情况,因此在3.0版本将其移除,比如getCaches
是个异步数据返回,无法保障数据的实时性渲染,因此在多标签页处理上,只需要自己定义tab数据数组即可,不需要对getCaches形成依赖,另外destroy方法调用也不是必须要的,在tab切换和打开新的tab当满足一定条件比如max达到数量之后Keepalive组件会自动将其销毁,因此建议只需要对自己定义的tabs数据数组进行增加和删除即可。
These were removed in version 3.0 due to the consideration that many scenarios might misuse them. For example, getCaches
is an asynchronous data return, which cannot guarantee the real-time rendering of data. Therefore, in handling multiple tabs, you only need to define your own tab data array and do not need to depend on getCaches
. Additionally, calling the destroy method is not mandatory; when switching tabs and opening new tabs, the Keepalive component will automatically destroy them once certain conditions are met, such as reaching the maximum count. Therefore, it is recommended to simply add and delete from your custom tab data array.
如果无法手动销毁缓存,关闭一个 tab 然后再次打开上次的内容还存在,对于应用来讲这应该是 bug 了,我认为手动销毁还是必须的,getCaches 是异步的也没啥问题,有的话直接销毁,没有缓存直接忽略就可以了。
这样的话确实会这样,因为缓存还在,不过大多数情况影响不大。getCaches和其他方法会加个补丁在下个小版本更新
https://github.com/irychen/keepalive-for-react/commit/b1f5c4d7190b96eb10d89afcfd60d6dc1320a0f7#diff-70a1ac362f8ce87279cb4b0a5f1e37dc0d615d5eea5b5570df550d861b9041ecL127-L151
getCaches、removeCache、cleanAllCache 以及 cleanOtherCache 在 3.0 版本被删除了,但是在多 tab 管理中需要用到这些方法,请求恢复这些被删除的方法。
当前有 destroy 方法了,似乎只需要提供 getCaches 方法就行了,其他的方法可以自己实现。