前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >微信小程序展示弹窗的几种方式

微信小程序展示弹窗的几种方式

作者头像
peng_tianyu
发布2022-12-15 17:16:58
4.1K0
发布2022-12-15 17:16:58
举报
文章被收录于专栏:前端开发随记前端开发随记

小程序中展示弹窗有四种方式:showToastshowModalshowLoadingshowActionSheet

官方文档链接

效果图

https://img-blog.csdnimg.cn/20200824143538219.gif#pic_center

wxml
代码语言:javascript
复制
<!-- 1.消息提示框 -->
<button size="mini" bindtap="handleShowToast">ShowToast</button>

<!-- 2.模态对话框 -->
<button size="mini" bindtap="handleShowModal">OnShowModal</button>

<!-- 3.loading提示框 -->
<button size="mini" bindtap="handleShowLoading">OnShowLoading</button>

<!-- 4.操作菜单 -->
<button size="mini" bindtap="handleShowAction">OnShowActionSheet</button>
js
代码语言:javascript
复制
Page({
  handleShowToast() {
    wx.showToast({
      title: '内容', //提示的内容
      duration: 2000, //持续的时间
      icon: 'loading', //图标
      mask: true //显示透明蒙层 防止触摸穿透
    })
  },
  handleShowModal() {
    wx.showModal({
      title: '我是标题', //提示的标题
      content: '我是内容,111' //提示的内容
      success: function(res) {
        if(res.confirm) {
          console.log('用户点击了确定')
        } else if(res.cancel) {
          console.log('用户点击了取消')
        }
      }
    })
  },
  handleShowLoading() {
    wx.showLoading({
      title: '加载中。。。', //提示的内容
      masl: true //显示透明蒙层 防止触摸穿透
    })
    //showLoading需要调用wx.hideLoading()关闭
    setTimeOut(() => {
      wx.hideLoading();
    }, 2000)
  },
  handleShowAction() {
    wx.showActionSheet({
      itemList: ['拍照','相机'] //文字数组
      success: (res) => {
        switch(res.tapIndex) {
          case 0:
            console.log('用户点击了拍照')
            break;
          case 1:
            console.log('用户点击了相机')
            break;	
        }
      }
    })
  }
})
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2020-08-24,如有侵权请联系 cloudcommunity@tencent.com 删除

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

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

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

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 小程序中展示弹窗有四种方式:showToast、showModal、showLoading、showActionSheet
    • 效果图
      • wxml
        • js
        相关产品与服务
        云开发 CloudBase
        云开发(Tencent CloudBase,TCB)是腾讯云提供的云原生一体化开发环境和工具平台,为200万+企业和开发者提供高可用、自动弹性扩缩的后端云服务,可用于云端一体化开发多种端应用(小程序、公众号、Web 应用等),避免了应用开发过程中繁琐的服务器搭建及运维,开发者可以专注于业务逻辑的实现,开发门槛更低,效率更高。
        领券
        问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档