uni-app使用uni.showModal时取消事件没有被触发 点取消也显示确认的事件
uni-app使用uni.showModal时取消事件没有被触发 点取消也显示确认的事件
| 类别 | 信息 |
|---|---|
| 产品分类 | uniapp/H5 |
| PC开发环境 | Windows |
| 操作系统版本 | 10 |
| HBuilderX类型 | 正式 |
| HBuilderX版本 | 3.1.7 |
| 浏览器平台 | Chrome |
| 项目创建方式 | HBuilderX |
示例代码:
点击取消按钮,浏览器打印确认事件
操作步骤:
点击取消按钮
预期结果:
打印出 456
实际结果:
打印出 123
bug描述:
uni.showModal({
content:'123',
success:()=>${
console.log('123')
},
fail:() => {
console.log('456')
}
})
更多关于uni-app使用uni.showModal时取消事件没有被触发 点取消也显示确认的事件的实战教程也可以访问 https://www.itying.com/category-93-b0.html
2 回复
更多关于uni-app使用uni.showModal时取消事件没有被触发 点取消也显示确认的事件的实战教程也可以访问 https://www.itying.com/category-93-b0.html
在uni-app中,uni.showModal的success回调函数会同时响应确认和取消操作,这是框架设计特性。根据官方文档,需要通过回调参数res.confirm来判断用户点击的是确认还是取消按钮。
请修改代码如下:
uni.showModal({
content: '123',
success: (res) => {
if (res.confirm) {
console.log('123') // 用户点击确认
} else if (res.cancel) {
console.log('456') // 用户点击取消
}
}
})

