wx.showModal
显示模态对话框
参数
object.success 回调函数
参数
示例代码
Demo1
wx.showModal({title: '提示',content: '这是一个模态弹窗',success (res) {if (res.confirm) {console.log('用户点击确定')} else if (res.cancel) {console.log('用户点击取消')}}})
效果
Demo2
wx.showModal({title: '删除图片',content: '确定要删除该图片?',showCancel: true,//是否显示取消按钮cancelText:"否",//默认是“取消”cancelColor:'skyblue',//取消文字的颜色confirmText:"是",//默认是“确定”confirmColor: 'skyblue',//确定文字的颜色success: function (res) {if (res.cancel) {//点击取消,默认隐藏弹框} else {//点击确定temp.splice(index, 1),that.setData({tempFilePaths: temp,})}},fail: function (res) {},//接口调用失败的回调函数complete: function (res) {},//接口调用结束的回调函数(调用成功、失败都会执行)})
效果
Demo3
wx.showModal({title: '温馨提示',content: "打卡成功~👍",success(res) {},fail(res) {},showCancel: false,confirmText: "确定", //默认是“确定”})
效果
注意
Android 6.7.2 以下版本,点击取消或蒙层时,回调 fail, errMsg 为 “fail cancel”;Android 6.7.2 及以上版本 和 iOS 点击蒙层不会关闭模态弹窗,所以尽量避免使用「取消」分支中实现业务逻辑参考
https://developers./miniprogram/dev/api/ui/interaction/wx.showModal.html