php toast 弹框,微信小程序API交互反馈,wx.showToast显示消息提示框

c1d18d0379d5a546975349e47c94537d.png

wx.showtoast(object)

显示消息提示框。

object参数说明:

参数类型必填说明最低版本

title

string

提示的内容

icon

string

图标,有效值"success"、"loading"

image

string

自定义图标的本地路径,image 的优先级高于 icon

1.1.0

duration

number

提示的延迟时间,单位毫秒,默认:1500

mask

boolean

是否显示透明蒙层,防止触摸穿透,默认:false

success

function

接口调用成功的回调函数

fail

function

接口调用失败的回调函数

complete

function

接口调用结束的回调函数(调用成功、失败都会执行)

示例代码:

wx.showtoast({

title: '成功',

icon: 'success',

duration: 2000

})

wx.showloading(object)

基础库版本 1.1.0 开始支持,低版本需做兼容处理

显示 loading 提示框, 需主动调用 wx.hideloading 才能关闭提示框

object参数说明:

参数类型必填说明

title

string

提示的内容

mask

boolean

是否显示透明蒙层,防止触摸穿透,默认:false

success

function

接口调用成功的回调函数

fail

function

接口调用失败的回调函数

complete

function

接口调用结束的回调函数(调用成功、失败都会执行)

wx.hidetoast()

隐藏消息提示框

wx.hideloading()

基础库版本 1.1.0 开始支持,低版本需做兼容处理

隐藏loading提示框

wx.showloading({

title: '加载中',

})

settimeout(function(){

wx.hideloading()

},2000)

wx.showmodal(object)

​显示模态弹窗

object参数说明:

参数类型必填说明

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

接口调用结束的回调函数(调用成功、失败都会执行)

succes返回参数说明:

参数类型说明最低版本

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('用户点击取消')

}

}

})

wx.showactionsheet(object)

​显示操作菜单

object参数说明:

参数类型必填说明

itemlist

string array

按钮的文字数组,数组长度最大为6个

itemcolor

hexcolor

按钮的文字颜色,默认为"#000000"

success

function

接口调用成功的回调函数,详见返回参数说明

fail

function

接口调用失败的回调函数

complete

function

接口调用结束的回调函数(调用成功、失败都会执行)

success返回参数说明:

参数类型说明

tapindex

number

用户点击的按钮,从上到下的顺序,从0开始

示例代码:

wx.showactionsheet({

itemlist: ['a', 'b', 'c'],

success: function(res) {

console.log(res.tapindex)

},

fail: function(res) {

console.log(res.errmsg)

}

})

bug & tip

bug:android6.3.30,wx.showmodal 的返回的 confirm 一直为 true;

tip: wx.showactionsheet 点击取消或蒙层时,回调fail, errmsg 为 "showactionsheet:fail cancel";

tip: wx.showloading 和 wx.showtoast 同时只能显示一个,使用 wx.hidetoast/wx.hideloading 都可以关闭提示框;

tip: ios wx.showmodal 点击蒙层不会关闭模态弹窗,所以尽量避免使用“取消”分支中实现业务逻辑。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值