简体   繁体   English

如何使用类星体框架在 javascript vue.js 中检测关闭选项卡/浏览器以注销

[英]How to detect Close Tab/ Browser for logout in javascript vue.js with quasar framework

I want to call the logout function on the close tab or close the browser only, not on the refresh page.我想在关闭选项卡上调用注销 function 或仅关闭浏览器,而不是在刷新页面上。
I tried with the below example code it doing logout on the close tab perfectly but also doing logout if I refresh the page.我尝试使用下面的示例代码,它完美地在关闭选项卡上注销,但如果我刷新页面,它也会注销。
I want to prevent logout on the refresh page.我想防止在刷新页面上注销。

 window.addEventListener('beforeunload', this.logout)

I added the below code in mounted() function and it works for me我在mounted() function 中添加了以下代码,它适用于我

 window.addEventListener("beforeunload", (event) => {
      // on the navigation type checking refresh or close tab/browser for logout

      console.log("performance.navigation.type " + performance.navigation.type);

      if (performance.navigation.type != 1) {
        this.logout();
      }
      return false;
    });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 javascript中如何检测浏览器标签关闭事件 - How to detect browser tab close event in javascript 使用 Quasar 框架和 Vue.js 将鼠标悬停在图像上时如何显示一些信息 - How to display some info when you hover on image using Quasar framework and Vue.js 如何使用 React js 检测浏览器标签关闭事件? - How to detect browser tab close event with react js? 使用 jquery/Javascript 在浏览器关闭或选项卡关闭时执行注销 - Perform logout on browser close or tab close using jquery/Javascript Vue.js单文件组件中的Mapbox-gl(Quasar-Framework) - Mapbox-gl in a Vue.js single file component (Quasar-Framework) 路径切换时组件未加载到页面中(Vue.js quasar 框架) - Components not loading into page upon path switch (Vue.js quasar framework) 在JavaScript中单击浏览器窗口或选项卡关闭时,如何实现注销功能? - How to implement logout functionality when clicked on browser window or tab close in JavaScript? 如何在 Bun.js 中使用 Quasar Framework 和/或 Vue3 - How to use Quasar Framework and/or Vue3 with Bun.js 如何检测浏览器窗口/标签关闭事件? - How to Detect Browser Window /Tab Close Event? 如何在浏览器选项卡中检测到关闭? - How can I detect a close in the browser tab?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM