![](https://i-blog.csdnimg.cn/blog_migrate/947b50d03a6a2a90c0cf01b54b7c54ed.png)
mounted() {
window.addEventListener('beforeunload', (e) => this.beforeunloadHandler(e));
window.addEventListener('unload', this.updateHandler);
},
methods: {
beforeunloadHandler(e) {
e = e || window.event;
if (e) {
e.returnValue = '关闭提示';
}
return '关闭提示';
},
updateHandler() {
fetch('url', {
method: 'POST',
body:'参数',
headers: {'Content-Type': 'application/json'},
keepalive: true
});
}
},