前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >微信小程序-常用弹窗

微信小程序-常用弹窗

作者头像
BNTang
发布2023-05-22 08:29:57
4510
发布2023-05-22 08:29:57
举报

showToast

image-20230521214112450
image-20230521214112450

showModal

image-20230521214105040
image-20230521214105040

showLoading

image-20230521214057592
image-20230521214057592

showActionSheet

image-20230521214043585
image-20230521214043585

页面结构文件:

代码语言:javascript
复制
<!--index.wxml-->
<button bindtap="onShowToast">showToast</button>
<button bindtap="onShowLoading">showLoading</button>
<button bindtap="onShowModal">showModal</button>
<button bindtap="onShowActionSheet">showActionSheet</button>

JS 逻辑文件:

代码语言:javascript
复制
// 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("点击了取消");
      }
    })
  }
})
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2023-05-21 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • showModal
  • showLoading
  • showActionSheet
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档