How does Cookie set the expiration time to clear when the current page is closed?

  Cookie.set("token", res.data.data.token);

how do I set the expiration time for Cookie on this basis? Set to clear when the page is closed?

Jun.21,2021

then why do you use Cookie,? this case is more suitable for Session Storage.


in this case, you can use session directly or use session storage


to try this when there is only one page, which means clear the cookie
< body onbeforeunload= "document.cookie=''" >


before the page closes.

clear cookie before unloading the page

window.addEventListener('beforeunload', funciton (){
    Cookie.set('token', null);
}, false)
Menu