需求
android端和ios端点击手机物理返回键(左上角的)或页面滑动键退出后,弹出弹框,点击确定后才退出该页面。
截图展示:
在这里插入图片描述
在这里插入图片描述
实现代码:
在onBackPress()方法中实现。
注意一定要在success后面加上.bind(this)代码,不然ios端会出现,点击物理返回键后,先退出该页面在出现弹框的问题。
亲测有效(ios端和android端已测)

onBackPress() {
	//console.log("press back");
	uni.showModal({
		title: '退出该页面后将关闭此次轨迹记录',
		confirmText: '退出',
		success: function(res) {
			if (res.confirm) {
				.....//此处把你退出后需要的方法写上就行
				this.stopGetLocation();
				this.started = false;
				this.imgpath = '../../static/open.png'
			}
		}.bind(this)//此处bind是关键
	})
},
Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐