[Vuejs]-Inject some logic into destroyed

0👍

As for VUE 2 – You can use a mixin as described here https://v2.vuejs.org/v2/guide/mixins.html

A mixin can contain a beforeDestroy or destroyed hook.

Hook functions with the same name are merged into an array so that all of them will be called. Mixin hooks will be called before the component’s own hooks.

You can also use a global mixin to address all components.

You can also apply a mixin globally. Use with caution! Once you apply a mixin globally, it will affect every Vue instance created afterwards.

Vue.mixin({
  destroyed() {
    console.log('Component has been destroyed logic');
  }
})

Leave a comment