微信小程序 --- toast消息提示框

toast:是用于进行提示用户的:

效果:

代码:

<toast hidden="{{onOff}}" duration="1000" bindchange="clickTap" >默认</toast>

注意:在上面设置了 duration ;但是时间到了也不会消失。原因这里的消失需要改的是 hidden=“true” 。这里只是时间到了会去触发 bindchange 事件。

所以:需要在 bindtap 里面设置让这个消失的方法。

除了这种方法:还可以用JS:

btnclick:function(){
    wx.showToast({
        title:'成功',
        icon:'success',
        duration:2000
    });
  //模拟取消
  setTimeout(function(){
    wx.hideToast(); 
  },2000); }

如果这个需要手动结束这个 toast,可以设置 10000:

具体参数

title:提示的内容。

icon:图标,只支持  success   loading

duration:提示的延迟时间,单位毫秒。

success:接口调用成功的回调函数

fail:接口调用失败的回调函数。

complete:主要调用接口的回调函数。

原文地址:https://www.cnblogs.com/e0yu/p/8489358.html