实现:
由于页面导航自带返回按钮,利用Vue周期钩子函数 beforeRouteLeave (to, from, next) {}
beforeRouteLeave 的三个参数分别是
1、to:要去的页面
2、from: 本页面地址
3:next 下一步
next(false)代表不进行操作。
问题:
只有第一次进入页面时,弹框才会弹出来,再次进入页面只出现蒙罩层,且只是一闪而过。
解决:
加一个计时器 setTimeout(()=>{}),网上搜罗来的,目前还不知为什么,知道了会补充。
beforeRouteLeave (to, from, next) {
// 1 操作来自关闭按钮(按钮点击flag)
console.log("我退出了")
setTimeout(() => {
Dialog.confirm({
title: '确认',
message: '确认离开直播间?',
})
.then(() => {
console.log(from.path ,from)
if(from.path === '/startLive'){
next();
this.quitGroup()
console.log("确认")
}
})
.catch(() => {
// on cancel
console.log("取消")
next(false)
});
},200)
},