uniapp点击返回上一页按钮弹出提示框是否确认保存信息

点击按钮时弹出提示框判断是否需要保存

代码


data() {
	return {
		flag: true //是否弹出返回提示框 
	}
},
onBackPress() {
			if (this.flag) {
				uni.showModal({
					title: "确定退出编辑?",
					content: "退出后内容不做保存",
					success: (res) => {
						if (res.confirm) {
							// console.log("确定返回");
							this.flag = false
							uni.navigateBack({
								delta: 1, //返回层数,2则上上页
							})
							return true
						} else {
							this.flag = true
							// console.log("取消");
							return true
						}
					}
				})
				return true
			} else {
				return false
			}
},

猜你喜欢

转载自blog.csdn.net/growb/article/details/130133761