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

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("查询失败")
      }
    })
  }
})
相关推荐
Ama_tor1 小时前
mini-program01の系统认识微信小程序开发
微信小程序·小程序
Klaus_Wei4 小时前
Notepad++正则表达全解
notepad++·正则表达·notepad搜索·正则搜索
毛毛三由10 小时前
基于svga+uniapp的微信小程序动画组件开发指南
微信小程序·uni-app·notepad++
一只一只妖12 小时前
uniapp小程序无感刷新token
前端·小程序·uni-app
编程毕设14 小时前
基于小程序的智能停车管理系统设计与开发
小程序
Kelaru15 小时前
本地Qwen中医问诊小程序系统开发
python·ai·小程序·flask·project
初晨未凉17 小时前
uniapp返回webview返回小程序并且跳转回webview
小程序·uni-app
Python智慧行囊19 小时前
微信小程序交互精髓:点击操作与状态管理实战
微信小程序·小程序·交互
铲子Zzz1 天前
Java使用接口AES进行加密+微信小程序接收解密
java·开发语言·微信小程序