vue2 keep-alive 清除缓存
使用场景
系统tab页需要保存页面状态,使用keep-alive缓存路由组件router-view,关闭tab页,或者重新打开路径相同但query不同的tab页时,需要手动清空指定页面的缓存。
router-view组件配置ref属性
<keep-alive>
<router-view ref="currRoutePage" :key="$route.path" />
</keep-alive>
获取缓存对象
const {cache, keys} = this.$refs.currRoutePage.$options.parent
cache, keys的数据结构
如何删除页面/asset/list的缓存
delete cache['/asset/list']
keys.splice(0, 1)
参考文献
https://www.jb51.net/article/219187.htm
https://blog.csdn.net/weixin_40466351/article/details/126153041