Vue listens for browser window close events

I want to clear cookie, after closing the window. How can I listen for the window closing event in vue?

Feb.28,2021

you can listen through window.onbeforeunload that before the window closes, you can declare a function and then clear cookie


window.onbeforeunload = function(){
    ... //do someting
}

what if onbeforeunload fails to execute an asynchronous request?

Menu