微信小程序的几种弹出提示框

本文介绍了微信小程序中四种常用的提示方式:wx.showToast用于简单消息提示,wx.showModal提供模态对话框功能,wx.showLoading展示加载提示,wx.showActionSheet则用于显示操作菜单,帮助提升用户体验。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.wx.showToast 消息提示框

//icon:success 成功图标,loading 加载图标 (7个汉字长度),none不显示(两行文字)
//image:设置自定义图标,优先级高于icon
//mask:显示蒙层
wx.showToast({
  title: '成功',
  icon: 'success',
  duration: 2000
})

//隐藏消息提示框
wx.hideToast({})

2.wx.showModal 模态对话框

//showCancel:是否显示取消按钮
//cancelText,cancelColor,confirmText,confirmColor可设置
wx.showModal({
  title: '提示',
  content: '这是一个模态弹窗',
  success (res) {
    if (res.confirm) {
      console.log('用户点击确定')
    } else if (res.cancel) {
      console.log('用户点击取消')
    }
  }
})

3.wx.showLoading loading 提示框

//需调用 wx.hideLoading 才能关闭提示框
wx.showLoading({
  title: '加载中',
})

setTimeout(function () {
  wx.hideLoading()
}, 2000)

//隐藏 loading 提示框
wx.hideLoading({})

4.wx.showActionSheet 显示操作菜单

wx.showActionSheet({
  itemList: ['A', 'B', 'C'],
  success (res) {
    console.log(res.tapIndex)
  },
  fail (res) {
    console.log(res.errMsg)
  }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值