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

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("查询失败")
      }
    })
  }
})
相关推荐
黑客飓风6 小时前
当GitHub宕机时,我们如何协作?
github·notepad++
fakaifa7 小时前
点大餐饮独立版系统源码v1.0.3+uniapp前端+搭建教程
小程序·uni-app·php·源码下载·点大餐饮·扫码点单
Dignity_呱12 小时前
如何在不发版时,实现小程序的 AB 测试?
前端·面试·微信小程序
说私域13 小时前
基于开源 AI 大模型 AI 智能名片 S2B2C 商城小程序视角下的企业组织能力建设与破圈升级
人工智能·小程序
fakaifa21 小时前
【最新版】CRMEB Pro版v3.4系统源码全开源+PC端+uniapp前端+搭建教程
人工智能·小程序·uni-app·php·crmeb·源码下载·crmebpro
2501_915918411 天前
iOS 应用上架全流程实践,从开发内测到正式发布的多工具组合方案
android·ios·小程序·https·uni-app·iphone·webview
上海云盾第一敬业销售1 天前
小程序被爬虫攻击,使用waf能防护吗?
爬虫·小程序
suncentwl1 天前
做一个答题pk小程序多少钱?
小程序·答题小程序·知识竞赛·答题pk软件
说私域1 天前
基于开源链动2+1模式AI智能名片S2B2C商城小程序的流量转化策略研究
人工智能·小程序
咸虾米_1 天前
微信小程序通过uni.chooseLocation打开地图选择位置,相关设置及可能出现的问题
微信小程序·小程序·uniapp开发·小程序地图api