|
|
@@ -0,0 +1,49 @@ |
|
|
|
import { Dialog } from 'vant'; |
|
|
|
export default { |
|
|
|
data() { |
|
|
|
return { |
|
|
|
currentUrl: "" |
|
|
|
} |
|
|
|
}, |
|
|
|
create() { |
|
|
|
console.log('初始化了'); |
|
|
|
}, |
|
|
|
mounted() { |
|
|
|
// this.currentUrl = window.location.href |
|
|
|
// 监听浏览器返回 |
|
|
|
window.addEventListener("popstate", this.beforeUnloadHandler, false) |
|
|
|
}, |
|
|
|
destroyed() { |
|
|
|
window.removeEventListener("popstate", this.beforeUnloadHandler, false) |
|
|
|
}, |
|
|
|
methods: { |
|
|
|
beforeUnloadHandler(event) { |
|
|
|
event.returnValue = "离开此页面?" // 此处返回任意字符串,不返回null即可,不能修改默认提示内容 |
|
|
|
// console.log('beforeUnloadHandler'); |
|
|
|
event.preventDefault(); |
|
|
|
event.returnValue = ''; |
|
|
|
const message = '确定离开页面吗?' |
|
|
|
event.returnValue = message |
|
|
|
return message |
|
|
|
}, |
|
|
|
|
|
|
|
}, |
|
|
|
beforeRouteLeave(to, from, next) { |
|
|
|
let that=this |
|
|
|
setTimeout(() => { |
|
|
|
Dialog.confirm({ |
|
|
|
message: '需要保存草稿吗?', |
|
|
|
cancelButtonText: '狠心离去', |
|
|
|
confirmButtonText:'保存' |
|
|
|
}) |
|
|
|
.then(async () => { |
|
|
|
await that.submit(2); // 保存草稿 |
|
|
|
next() |
|
|
|
}) |
|
|
|
.catch(() => { |
|
|
|
next() |
|
|
|
}) |
|
|
|
},200) |
|
|
|
} |
|
|
|
|
|
|
|
} |