vue实现关闭浏览器窗口和刷新窗口执行事件
记录一些技术基础
·
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))
}
更多推荐
所有评论(0)