How does vue listen for browser refresh events? It's not just an event triggered by the destruction of a page.

the current requirement is that some component records a sessionStorage status when the page is refreshed, but not under the condition of a route jump.
so neither destroyed nor beforeDestroy is suitable.
the onbeforeunload method searched on the Internet is not clear where to use it. When you try to call it in beforeDestroy, it does not trigger the method. What hook function should be used in
Vue to execute the onbeforeunload method? Or what is a better way for Vue to listen for browser refresh events?

Apr.09,2021

created or mounted is fine.

window.addEventListener('beforeunload', e => {
    localStorage.setItem('abcde', 'asdas');
});
Menu