```
data() {
return:{
_gap_time: 0,
_beforeUnload_time: 0,
}
}
mounted() {
window.addEventListener('beforeunload', e=> this.beforeunloadFn())
window.addEventListener('unload', e=> this.unloadFn())
},
methods: {
unloadFn() {
this._gap_time = new Date().getTime() - this._beforeUnload_time
if (this._gap_time <= 5) {
//关闭窗口
}
},
beforeunloadFn() {
this._beforeUnload_time = new Date().getTime()
},
},
deactivated() {
window.removeEventListener('beforeunload', e=> this.beforeunloadFn());
window.removeEventListener('unload', e=> this.unloadFn());
},
```