mounted() {
window.addEventListener('beforeunload', e => this.beforeunloadHandler(e))
window.addEventListener('unload', e => this.unloadHandler(e))
},
destroyed() {
window.removeEventListener('beforeunload', e => this.beforeunloadHandler(e))
window.removeEventListener('unload', e => this.unloadHandler(e))
},
methods: {
beforeunloadHandler(){
this._beforeUnload_time=new Date().getTime();
},
unloadHandler(e){
this._gap_time=new Date().getTime()-this._beforeUnload_time;
debugger
//判断是窗口关闭还是刷新
if(this._gap_time<=5){
//处理的事情
}
},
}
Vue中监听窗口关闭事件,并在窗口关闭前发送请求
最新推荐文章于 2024-06-21 16:24:40 发布