//当showCancel为true时,event.from值第二次不一样
//当showCancel为false时,event.from值每次是一样的
onBackPress(event) {
console.log("e", event);
//e, [Object] {"from":"backbutton"}
if (event.from == 'backbutton') {
uni.showModal({
title: '提示',
content: '退出后已填写的数据会丢失,是否继续退出?',
showCancel: true,
confirmText: '退出',
success: (res) => {
if (res.confirm) {
uni.navigateBack()
}
}
})
return true;
}
},

- 发布:2022-06-24 14:09
- 更新:2022-06-27 11:30
- 阅读:709
产品分类: uniapp/App
PC开发环境操作系统: Windows
PC开发环境操作系统版本号: win10
HBuilderX类型: 正式
HBuilderX版本号: 3.4.15
手机系统: Android
手机系统版本号: Android 12
手机厂商: 小米
手机机型: 12
页面类型: vue
vue版本: vue2
打包方式: 云端
项目创建方式: HBuilderX
示例代码:
操作步骤:
1.复制示例代码,执行返回操作
2.查看日志
1.复制示例代码,执行返回操作
2.查看日志
预期结果:
event.from的值每次都应该是backbutton才对
event.from的值每次都应该是backbutton才对
实际结果:
event.from的值会因为showModal的showCancel属性为true的情况下在第二次执行返回时变为navigateBack
event.from的值会因为showModal的showCancel属性为true的情况下在第二次执行返回时变为navigateBack
bug描述:
onBackPress(event) 中event.from的值会因为showModal的showCancel属性为true的情况下在第二次执行返回时变为navigateBack
justR (作者)
我刚刚重新测试了一遍,找到原因了,modal的回调有问题,在有modal的情况下,执行页面返回操作会回调modal的success,并且当showCancel是false时,回调的res.confirm是false,反之是true,所以导致我上面的示例代码中执行了uni.navigateBack()。
2022-06-27 13:36