微信小程序:按钮禁用,避免按钮重复提交

wxml

html 复制代码
<view class="modal-buttons">
  <view class="one_btn" bindtap="submit">确认</view>
  <view class="two_btn" bindtap="cancel">取消</view>
</view>

wxss

css 复制代码
/* 按钮 */
.modal-buttons {
  width: 100%;
  height:7%;
  display: flex;
  font-weight:bold;
}
.one_btn{
  flex:1;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: #4b97e7;
  border-top: 1rpx solid #4b97e7;
  color: #fff;
  border-radius: 0;
}
.two_btn{
  flex:1;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  border-top: 1rpx solid #4b97e7;
  border-radius: 0px;
  background-color: #fff;
  color: #4b97e7;
}

js

javascript 复制代码
const app = getApp()
Page({
  data: {
    submitting:false//设置按钮禁用参数,默认为非禁用状态
  },
  //确认
  submit(){
    var that = this;
    if (that.data.submitting) {
      return; // 如果正在提交中,则直接返回,避免重复提交
    }
    // 禁用提交按钮
    that.setData({
      submitting: true,
    });
    console.log('执行下面的方法')
    wx.request({
      url: app.globalData.position + 'Produce/test',
      data: {
        wip_id: options.id
      },
      header: {
        "Content-Type": "application/x-www-form-urlencoded"
      },
      method: 'POST',
      dataType: 'json',
      success: res => {
        //请求完成,取消禁用
        that.setData({
          submitting: false, //取消禁用
        });
      },
      fail(res) {
        //请求完成,取消禁用
        that.setData({
          submitting: false, //取消禁用
        });
        console.log("查询失败")
      }
    })
  }
})
相关推荐
烟囱土著10 小时前
如何让相册「动」起来❓看这里❗
微信·微信小程序·小程序
azhou的代码园17 小时前
基于SpringBoot与微信小程序的招聘管理系统的设计与实现
spring boot·微信小程序·毕业设计·求职招聘小程序
蓝帆傲亦19 小时前
Web前端Mock数据实战指南:正确使用Mock.js提升开发效率
微信小程序·小程序·uni-app
00后程序员张19 小时前
iOS 应用代码混淆,对已编译 IPA 进行类与方法混淆
android·ios·小程序·https·uni-app·iphone·webview
kyh100338112019 小时前
微信小游戏《找茬找汉字闯关王》开发实战:送全部源码
microsoft·微信·微信小程序·小程序·微信小游戏·汉字找茬找梗
汤姆yu21 小时前
基于微信小程序的校园快递代取系统
微信小程序·小程序
albert-einstein21 小时前
微信小程序反编译(不通过模拟器进行反编译)
微信小程序·小程序
CodeLove·逻辑情感实验室2 天前
2026年度深度测评:亲测3款免费“聊天回复”神器,谁才是社交黑科技?
科技·小程序·aigc·aigc实测
2501_915918412 天前
mobileprovision 描述文件内容查看,查看 Bundle ID、证书指纹等来定位安装与签名问题
android·ios·小程序·https·uni-app·iphone·webview
毕设源码纪师姐2 天前
计算机毕设 java 基于微信小程序的社区物资订购系统 基于 SpringBoot 的微信小程序社区物资采购平台 Java 社区物资订购与配送管理系统
java·微信小程序·课程设计