[Vuejs]-How can I auto logout vue app after tab is closed?

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>

Leave a comment