微信小程序4种弹框

1、wx.showModal 确认弹框

javascript 复制代码
 delete(){
    wx.showModal({
      title: '',
      content: '是否确认删除',
      success(res) {
        if (res.confirm) {
          console.log('用户点击确定')
        } else if (res.cancel) {
          console.log('用户点击取消')
        }
      }
    })
  }

2、wx.showToast 提示弹框

|---------|--------|
| success | 显示成功图标 |
| error | 显示失败图标 |
| loading | 显示加载图标 |
| none | 不显示图标 |

|---|---|
| | |

javascript 复制代码
wx.showToast({
  title: '成功',
  icon: 'success',
  duration: 2000
})

3、wx.showLoading loading弹框

javascript 复制代码
wx.showLoading({
  title: '加载中',
})

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

4、wx.showActionSheet 操作弹框

javascript 复制代码
wx.showActionSheet({
  itemList: ['A', 'B', 'C'],
  success (res) {
    console.log(res.tapIndex)
  },
  fail (res) {
    console.log(res.errMsg)
  }
})

customer.wxml

XML 复制代码
<button class="fixed-service"  bindtap="getPhone">

  <text class="iconfont icon-kefu"></text>

  <view>客服</view>

</button>

customer.css

css 复制代码
/* 联系客服 */

.fixed-service {
  display: inline-block;
  bottom: 13%;
  right: 30rpx;
  width: 80rpx;
  height: 80rpx;
  position: fixed;
  background: rgba(0, 0, 0, 0.5);
  border-radius: 50%;
  text-align: center;
  color: #fff;
  box-sizing: border-box;
  font-size: 20rpx;
  padding: 10rpx;
  line-height: 1.2;
  z-index: 100;
}
.fixed-share .iconfont {
  font-size: 30rpx;
}

customer.js

javascript 复制代码
  getPhone:function (params) {
    var that=this;
    let arr=[];
		wx.request({
			url: newurl.getKfPhone,
			method: 'post',
			success (res) {
				if (res.data.status == 200) {
					console.log(res.data.data);
					that.setData({
							kfphone: res.data.data,
          });
          wx.showActionSheet({
            itemList:['拨打客服电话1','拨打客服电话2'], //文字数组
            success: (ress) => {
              switch(ress.tapIndex) {
                case 0:
                  console.log(res.data.data.kfphone1)
                  wx.makePhoneCall({
                    phoneNumber: res.data.data.kfphone1
                  });
                  break;
                case 1:
                  wx.makePhoneCall({
                    phoneNumber: res.data.data.kfphone2
                  });
                  console.log(res.data.data.kfphone2)
                  break;	
              };
            
            },
            fail (ress) {
              console.log('取消选项')
            }
          })
			} 
			}
		});
  },
相关推荐
h_65432105 小时前
微信小程序点击按钮跳转链接并显示
微信小程序·小程序
银迢迢8 小时前
微信小程序的开发及问题解决
微信小程序·小程序
liyinchi19888 小时前
原生微信小程序 textarea组件placeholder无法换行的问题解决办法
微信小程序·小程序
说私域10 小时前
基于开源链动2+1模式AI智能名片S2B2C商城小程序的低集中度市场运营策略研究
人工智能·小程序·开源·零售
少恭写代码13 小时前
duxapp 2025-03-29 更新 编译结束的复制逻辑等
react native·小程序·taro
suncentwl14 小时前
答题pk小程序道具卡的获取与应用
小程序·答题小程序·知识竞赛
bysjlwdx14 小时前
uniapp婚纱预约小程序
小程序·uni-app
ALLSectorSorft14 小时前
代驾小程序订单系统框架搭建
小程序·代驾小程序
qq_124987075314 小时前
原生小程序+springboot+vue+协同过滤算法的音乐推荐系统(源码+论文+讲解+安装+部署+调试)
java·spring boot·后端·小程序·毕业设计·课程设计·协同过滤
前端极客探险家1 天前
微信小程序全解析:从入门到实战
微信小程序·小程序