mounted() {
window.onbeforeunload = function (e) {
confirm('exit?')
}
}
mounted() {
window.onbeforeunload = ()=>{
this.close(); //自定义methods的close方法
}
}
' 生效mounted() {
window.onbeforeunload = function (e) {
e = e || window.event;
if (e) {
e.returnValue = "关闭提示";
}
return "关闭提示";
};
}
'当该事件返回的字符串(事前设置好的event.returnValue的值)不为null或者undefined时,弹出确认窗口让用户自行选择是否关闭当前页面。
MDN