行业知识
uniapp 禁止手机单页面侧滑返回(IOS禁止侧滑)
2026-11-01 09:43:48
来源:互联网转载
公司需求在监测心率时没有结束就不能退出页面,搜了很多IOS都没有效果,下边是我亲测IOS单页面使用有效
安卓方法:
export default { data() {return {canLeave: false}}, onBackPress() { if (this.canLeave) { // 当可以离开时,不阻止页面后退 return false; } else { // 当不可离开时,弹出提示 uni.showModal({ title: '提示', content: '是否确定退出当前页面?', success: res => { if (res.confirm) { // 用户点击确定 this.canLeave = true; // 允许离开 uni.navigateBack(); // 执行页面后退操作 } } }); // 阻止默认的页面后退 return true;}},} 这个方法适用于安卓和ios点击返回键返回时调用的
IOS侧滑我是直接在pages.json中关闭侧滑的,刚好符合我的需求
{"path": "pages/Equipment/smartWatches/heart-rate/index","style": {"navigationBarTitleText": "心率测量","navigationBarBackgroundColor": "#1E212E",//禁止滑动返回"disableSwipeBack": true,//禁止上下滑动"disableScroll": true}},