vue 清除keep-Alive 页面缓存
在Vue开发中用keep-alive 可以缓存页面状态,防止重新渲染DOM,在对页面性能优化上有好处,
有利也就有弊,对于想清除页面缓存我们该怎么做呢?
如下
beforeRouteLeave(to, from, next) {
if (to.name === 'login') {
this.$vnode.parent.componentInstance.cache = {}
this.$vnode.parent.componentInstance.keys = []
}
next();
},
在登出的是时候清除组件的状态