Vue 中发送请求时防止按钮多次点击
https://blog.csdn.net/weixin_40800926/article/details/103923698https://blog.csdn.net/Kotoba209_/article/details/103391836<el-button type="button" :disabled="isDisable" @click="fn1">发送请求<...
https://blog.csdn.net/weixin_40800926/article/details/103923698
https://blog.csdn.net/Kotoba209_/article/details/103391836
一、事件触发顺序
PC网页上的大部分操作都是用鼠标的,即响应的是鼠标事件,包括mousedown
、mouseup
、mousemove
和click
事件。一次点击行为,可被拆解成:mousedown
-> mouseup
-> click
三步。
手机上没有鼠标,所以就用触摸事件去实现类似的功能。touch事件包含touchstart
、touchmove
、touchend
,注意手机上并没有tap
事件。手指触发触摸事件的过程为:touchstart
-> touchmove
-> touchend
。
手机上没有鼠标,但不代表手机不能响应mouse事件(其实是借助touch去触发mouse事件)。也就是说在移动端的click事件可以拆解为:touchstart
-> touchmove
-> touchend -> click。
浏览器在 touchend 之后会等待约 300ms ,如果没有 tap 行为,则触发 click 事件。 而浏览器等待约 300ms 的原因是,判断用户是否是双击(double tap)行为,双击过程中就不适合触发 click 事件了。 由此可以看出 click 事件触发代表一轮触摸事件的结束。
上面说到原生事件中并没有 tap 事件,可以参考经典的 zepto.js 对 singleTap 事件的处理。
可以看出,singleTap 事件的触发时机 —— 在 touchend 事件响应 250ms 无操作后,触发singleTap。
<el-button type="button" :disabled="isDisable" @click="fn1">发送请求</el-button>
export default {
data() {
return {
isDisable:false,//防止多次提交
};
},
methods:{
async fn1(){
this.isDisable = true;//点击后禁用该按钮;
this.changeMedicinal = this.inferenceData[this.deductionIndex].prescData;
const response = await autograph(this,this.disease,this.diseaseElement,this.drugState,this.inferenceTransferId,this.patientId,this.changeMedicinal,this.treat,this.visitId);
const data = response.data;
var that = this;
if(response.code == 0){
this.$message({
message: '提交成功!',
type: "success",
duration: 2000
});
}
setTimeout(() => {
this.isDisable = false;//响应后延迟几秒回复正常;
}, 2500)
}
}
}
更多推荐
所有评论(0)