Why the method of vm.$destroy () doesn't work

Hook function before the route leaves
beforeRouteLeave (to, from, next) {

    const vm = this;
    vm.$destroy();
    next();
},
thisdestroyactivated
Feb.21,2022

you should not destroy the current component, but the keep-alive wrapped by destroy. Refer to the keep-alive.js in the vue source code as follows:

destroyed () {
    for (const key in this.cache) {
        //
      pruneCacheEntry(this.cache, key, this.keys)
    }
  }

so, as long as you drop the keep-alive to destroy, your cached components will be destroyed naturally.

Menu