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))
}
vue实现关闭浏览器窗口和刷新窗口执行事件
最新推荐文章于 2024-08-27 22:17:50 发布