解决vue 按钮多次点击重复提交问题

做项目时通常会遇到点击2次或多次表单按钮会重复提交数据,解决这个问题,需要将提交按钮置灰。可以通过disabled控制按钮的点击和不可点击,下面举个例子

<Button type="primary" @click="bookok" :disabled="isDisable">确定</Button>
<script>
    export default {
         return {
                isDisable: false,//表单重复提交
          },
          methods: {
           bookok() {
	    	  this.isDisable = true  //开始可以点击
		      this.post("api/student/Bespeak/getBespeak", {
		          'stuId':this.rowData.stuId,
			        'bespeakId':this.rowData.bespeakId,
			        'courseId':this.courseId
		      }).then(data => {
		      	 this.isDisable = false;//执行请求后就不能点击了
		        if (data.code == 0) {
		        	this.isShow = true
		        	this.$Message.success("预约成功");
							this.btnSearch() 
		        } else {
		          this.$Message.error(data.msg);
		        }
		      });
	    },
          } 
    }
</script>

猜你喜欢

转载自blog.csdn.net/jxg1473819657/article/details/83781364