目录
非 VIP 用户可前往公众号“前端基地”进行免费阅读,文章链接如下:
wx.showToast
显示消息提示框
示例代码如下:
showToast.wxml
<view class="w flex">
<button type="primary" bindtap="showSuccessToast">显示成功图标</button>
<button type="warn" bindtap="showErrorToast">显示失败图标</button>
<button type="primary" bindtap="showLoadingToast">显示加载图标</button>
<button type="primary" bindtap="showNoneToast">不显示图标</button>
<button type="primary" bindtap="showDiyToast">自定义图标</button>
</view>
showToast.js
Page({
showErrorToast(){
wx.showToast({
title: '显示失败图标',
icon:'error'
})
},
showSuccessToast(){
wx.showToast({
title: '显示成功图标'
})
},
showLoadingToast(){
wx.showToast({
title: '显示加载图标',
icon:'loading'
})
},
showNoneToast(){
wx.showToast({
title: '不显示图标',
icon:'none'
})
},
showDiyToast(){
wx.showToast({
title: '自定义图标',
image:'../../images/icon.jpg'
})
}
})
运行结果:
点击“显示成功图标”按钮,显示成功图标的消息提示框,截图如下:
点击“显示失败图标”按钮,显示失败图标的消息提示框,截图如下: