0👍
I think you can use this way
window.addEventListener('beforeunload', function (e) {
window.localStorage.clear();
});
Or more affective for Vue Js use
<script>
export default {
created() {
window.addEventListener('beforeunload', (event) => {
// Cancel the event as stated by the standard.
event.preventDefault();
// Chrome requires returnValue to be set.
event.returnValue = '';
});
}
}
</script>
Source:stackexchange.com