so far as I know, if you close or refresh a page,the hook 'beforedestroy' and 'destroyed' in Vue would not be triggered.So maybe I can use
window.onbeforeunload = function() { ... }
And here's the code
mounted() {
window.onbeforeunload = function() {
window.localStorage.setItem('form', JSON.stringify(this.form))
}
}
However, What I store is undefined. So I think that the instance has been destroyed when the function is called. In this way, this.form can't be accessed.Is there any other way?