keepAlive 缓存手动移除

beforeRouteLeave (to, from, next) {
    if (to.path === '/index/apps') {
      // from.meta.keepAlive = false
      if (this.$vnode && this.$vnode.data.keepAlive) {
        if (this.$vnode.parent && this.$vnode.parent.componentInstance && this.$vnode.parent.componentInstance.cache) {
          if (this.$vnode.componentOptions) {
            var key = this.$vnode.key == null ? this.$vnode.componentOptions.Ctor.cid + (this.$vnode.componentOptions.tag ? `::${this.$vnode.componentOptions.tag}` : '') : this.$vnode.key
            var cache = this.$vnode.parent.componentInstance.cache
            var keys = this.$vnode.parent.componentInstance.keys
            if (cache[key]) {
              if (keys.length) {
                var index = keys.indexOf(key)
                if (index > -1) {
                  keys.splice(index, 1)
                }
              }
              delete cache[key]
            }
          }
        }
        from.meta.keepAlive = true
      }
    } else {
      from.meta.keepAlive = true
    }
    next()
  }

  

posted @ 2020-03-31 15:30  言穹  阅读(1796)  评论(0编辑  收藏  举报