微信小程序的页面交互

wx.showToast和wx.showModal

wx.showToast(显示消息提示框

参数说明:

参数 类型 必填 说明 最低版本
title String 提示的内容  
icon String 图标,有效值 "success", "loading", "none"  
image String 自定义图标的本地路径,image 的优先级高于 icon 1.1.0
duration Number 提示的延迟时间,单位毫秒,默认:1500  
mask Boolean 是否显示透明蒙层,防止触摸穿透,默认:false  
success Function 接口调用成功的回调函数  
fail Function 接口调用失败的回调函数  
complete Function 接口调用结束的回调函数(调用成功、失败都会执行)

icon有效值

有效值 说明 最低版本
success 显示成功图标,此时 title 文本最多显示 7 个汉字长度。默认值  
loading 显示加载图标,此时 title 文本最多显示 7 个汉字长度。  
none 不显示图标,此时 title 文本最多可显示两行 1.9.0

示例代码:

wx.showToast({
  title: '成功',
  icon: 'success',
  duration: 2000
})

wx.showModal(​显示模态弹窗)

参数说明:

参数 类型 必填 说明
title String 提示的标题
content String 提示的内容
showCancel Boolean 是否显示取消按钮,默认为 true
cancelText String 取消按钮的文字,默认为"取消",最多 4 个字符
cancelColor HexColor 取消按钮的文字颜色,默认为"#000000"
confirmText String 确定按钮的文字,默认为"确定",最多 4 个字符
confirmColor HexColor 确定按钮的文字颜色,默认为"#3CC51F"
success Function 接口调用成功的回调函数
fail Function 接口调用失败的回调函数
complete Function 接口调用结束的回调函数(调用成功、失败都会执行)

success返回参数说明:

参数 类型 说明 最低版本
confirm Boolean 为 true 时,表示用户点击了确定按钮  
cancel Boolean 为 true 时,表示用户点击了取消(用于 Android 系统区分点击蒙层关闭还是点击取消按钮关闭) 1.1.0

示例代码:

wx.showModal({
  title: '提示',
  content: '这是一个模态弹窗',
  success: function(res) {
    if (res.confirm) {
      console.log('用户点击确定')
    } else if (res.cancel) {
      console.log('用户点击取消')
    }
  }
})

猜你喜欢

转载自blog.csdn.net/csjn_y/article/details/80277458