mounted(){

    window.addEventListener('beforeunload', e => this.beforeunloadHandler(e))
    window.addEventListener('unload', e => this.unloadHandler(e))
 }
 beforeunloadHandler(e){
      this.beforeUnloadTime=new Date().getTime();
    }
    unloadHandler(e){
      this.gapTime=new Date().getTime()-this.beforeUnloadTime;
      //判断是窗口关闭还是刷新
      if(this.gapTime<=5){//关闭做事
   this.deviceIdList.forEach(e=>{
      //console.log(e)
      var d = e.split("-")[0];
      var c = e.split("-")[1];
      this.cutOutFlow(d,Number(c));
    })
      }else{//刷新做事
........
}
    }
  destroyed() {
    window.removeEventListener('beforeunload', e => this.beforeunloadHandler(e))
    window.removeEventListener('unload', e => this.unloadHandler(e))
  }

Logo

基于 Vue 的企业级 UI 组件库和中后台系统解决方案,为数万开发者服务。

更多推荐