当在一个表单页面 填写了很多数据,或者编辑页面数据发生变动之后,这时候返回上一个页面需要提醒用户是否返回的弹框
wx.enableAlertBeforeUnload({
message: "您内容已更新,还没保存,确定要退出吗?",
success: function (res) {
},
fail: function (err) {
console.log("失败:", err);
},
});
wx.disableAlertBeforeUnload()
beforeleave() {
this.showPage = false
uni.showModal({
title: 内容发生改变,确定要退出吗?,
success: (e) => {
if (e.confirm) {
uni.navigateBack(1)
} else {
//点击取消之后再次开启弹框阻止用户
this.showPage = true
}
},
})
},