1,vue使用组件内路由
beforeRouteLeave(to, from, next) {
let a=comfirm('确定离开’)
next(a)
}
2,js实现
前端页面关闭或者刷新事件 onbeforeunload
页面加载时只执行onload
页面关闭时先执行onbeforeunload,最后onunload
页面刷新时先执行onbeforeunload,然后onunload,最后onload。
window.onbeforeunload = function(event) { return confirm("确定离开此页面吗?"); }
也可以再onunload那里实现