vue防止重复点击提交

<input type="button" name="" id="" @click="save()" value="发表评价"  :disabled="isDisable"/>
data:()=>({
  isDisable: false
}),
methods: {
  save() {//保存评价

      for (let k = 0; k < this.imgList.length; k++) {
        if(k<this.imgList.length-1)
        {
          this.mgcoImage += this.imgList[k] + ","
        }else {
          this.mgcoImage += this.imgList[k]
        }
      }
    this.isDisable = true
      // for (var i=0;i<this.mgcoOrderDetailIds.length;i++) {
      this.mgcoOrderDetailId=this.mgcoOrderDetailIds[0]
      Order.releaseEvaluation({mgcoOrderDetailId:this.mgcoOrderDetailId,mgcoStar:this.mgcoStar,mgcoContent:this.mgcoContent,mgcoIsAnonymous:this.mgcoIsAnonymous,mgcoImage:this.mgcoImage}).then(res => {
        if (res.data.flag) {
          this.isDisable = false
          this.$layer.msg(res.data.msg, {offset: 'rb'})
          this.$router.push('/orders/' + 4)
        } else {
          this.$layer.msg(res.data.msg, {offset: 'rb'})
        }
      })
      // }

  },

这个其实是一个很细节的问题。 如果我们操作一个按钮,然后在按钮点击的时候绑定事件。 
事件分为两种情况:

  • 第一种: 不操作数据型
  • 第二种: 操作数据型
<template>
  <button @click="submit()" :disabled="isDisable">点击</button>
</template>

<script>
  export default {
    name: 'TestButton',
    data: function () {
      return {
        isDisable: false
      }
    },
    methods: {
      submit() {
        this.isDisable = true
        setTimeout(() => {
          this.isDisable = false
        }, 1000)
      }
    },
  }
</script>

这里我们通过控制 isDisable 来设置 disabled来控制按钮的点击和不可点击 。 默认isDisable:的值为 false,按钮可以点击。 当我们点击这个按钮的时候,首先将按钮的绑定isDisable设置为true,1秒后立马将其置为false。 所以用户只能有一秒的时间去操作这个按钮。

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值