[Vuejs]-Add a callback to a Vue instance's destroy hook

5👍

OK, looks like we can use instance.$once("hook:beforeDestroy", () => { to add callbacks to hooks!

A example would be:

const instance = new Vue({});

instance.$once("hook:beforeDestroy", () => {
  console.log('Destroying!');
});

setTimeout(() => {
  instance.$destroy();
}, 1000);
<script src="https://vuejs.org/js/vue.min.js"></script>
👤Rikard

Leave a comment