0👍
✅
Found a solution for my problem. I was putting the onbeforeunload
event in the wrong place. And, in my case, the onbeforeunload
wasn’t the answer. To log out the user I just needed to call:
import { EventBus } from "@/services/eventBus"
window.onunload = function () {
EventBus.$emit("onunload")
}
… in main.js
. Then, I was able to listen to this event and call a function in the .vue
file:
mounted() {
EventBus.$on("onunload", this.logout);
},
Source:stackexchange.com