微信小程序-常用弹窗
  0nZj5jIUY2eL 2023年11月02日 105 0


官方文档:https://developers.weixin.qq.com/miniprogram/dev/api/ui/interaction/wx.showToast.html

showToast

微信小程序-常用弹窗_xml

showModal

微信小程序-常用弹窗_小程序_02

showLoading

微信小程序-常用弹窗_小程序_03

showActionSheet

微信小程序-常用弹窗_小程序_04

页面结构文件:

<!--index.wxml-->
<button bindtap="onShowToast">showToast</button>
<button bindtap="onShowLoading">showLoading</button>
<button bindtap="onShowModal">showModal</button>
<button bindtap="onShowActionSheet">showActionSheet</button>

JS 逻辑文件:

// index.js
Page({
  onShowToast() {
    wx.showToast({
      title: '成功',
      icon: "success",
      duration: 3000,
      mask: true,
      success() {
        console.log("显示成功");
      },
      fail() {
        console.log("显示失败");
      },
      complete() {
        console.log("complete");
      }
    })
  },
  onShowLoading() {
    wx.showLoading({
      title: '加载中',
    })

    // 注意点:不会主动消失,其它的和showToast差不多
    setTimeout(function () {
      wx.hideLoading()
    }, 2000)
  },
  onShowModal() {
    wx.showModal({
      title: '我是标题',
      content: '我是内容',
      cancelText: "撤退",
      cancelColor: "#00f",
      confirmText: "确认",
      confirmColor: "#f00",
      complete: (res) => {
        if (res.cancel) {
          console.log('点击了取消按钮');
        }

        if (res.confirm) {
          console.log('点击了确认按钮');
        }
      }
    })
  },
  onShowActionSheet() {
    wx.showActionSheet({
      itemList: ["电脑", "手机", "家具"],
      itemColor: '#f00',
      success (res) {
        console.log(res.tapIndex)
      },
      fail (res) {
        console.log(res.errMsg)
        console.log("点击了取消");
      }
    })
  }
})
【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年11月08日 0

暂无评论

推荐阅读
0nZj5jIUY2eL