beforeRouteLeave (to, from, next) {
if (this.isBack) {
next()
} else {
setTimeout(() => {
this.$dialog.alert({
title: '当前数据还未保存,是否确认退出?',
confirmButtonColor: '#1da4f2', // 确认按钮颜色
showCancelButton: true, // 是否显示取消按钮
closeOnClickOverlay: true
}).then(() => {
next()
}).catch(() => {
next(false)
})
}, 100)
}
}
可以设置一个定时器然后就好了
借鉴于 这位博主beforeRouteLeave路由守卫,退出页面时弹窗提示_hello_kking的博客-CSDN博客_beforerouteleave