removeKeepAlive() {
//动态删除缓存
var vn = this.$vnode,
p = vn && vn.parent
if (!vn || !vn.data.keepAlive || !vn.componentOptions) return
if (!p || !p.componentInstance || !p.componentInstance.cache) return
var key =
vn.key ||
vn.componentOptions.Ctor.cid +
(vn.componentOptions.tag ? `::${vn.componentOptions.tag}` : "")
var cache = p.componentInstance.cache
var keys = p.componentInstance.keys
if (cache[key]) {
if (keys.length) {
var index = keys.indexOf(key)
if (index > -1) {
keys.splice(index, 1)
}
}
delete cache[key]
}
this.$destroy()
}
上面代码已经封装成了函数,放js中调用即可,运行后 keep-alive 标签缓存会被清除