[Vuejs]-How to remove localstorage in javascript after some time

0๐Ÿ‘

โœ…

As Estus Flask and Samuel Liew also suggested to use sessionStorage as per the requirement you have. But still if you want to use localStorage for any reasons. You can use :

localStorage.removeItem(<your item comes here>)

Called this inside beforeDestroy() hook as it called right before a vue instance destroy.

This will ensure that before the instance is removed from the DOM, we are removing an item from the localStorage.

0๐Ÿ‘

You can use session or cookie storage for that purpose, but if you want to use local storage then you can use onunload or onbeforeunload event listeners of JS and clear local storage on onunload. These listeners work perfectly on tab close or tab back button as well.

Leave a comment