Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is Vue's 'destroyed' method called on page refresh?

I am wondering if refreshing a page that runs a Vue app will trigger the Vue's .destroyed callback.

From what I observed in a Vue app that contains these simple lifecycle callbacks:

created() {
  console.log(' created');
},
destroyed() {
  console.log('destroyed');
}

only 'created' is logged (not 'destroyed'). How can I check if the .destroyed callback has been executed?

like image 619
user7693832 Avatar asked Jan 27 '23 08:01

user7693832


1 Answers

I found the similar question and answer to it on stackoverflow

Do something before reload or close in vue.js

He/she basically explains that nothing is destroyed on page reload, you need to define

window.onbeforeunload = function(){
  return "Are you sure you want to close the window?";
}

If you want to do something before a page refresh

like image 68
onuriltan Avatar answered Jan 29 '23 08:01

onuriltan