原文地址:https://blog.csdn.net/misschengispink/article/details/122963606
按钮频繁操作会导致发多个请求,消耗性能而且请求混乱会导致一些bug出现,所以在写按钮操作的时候就应该考虑周全,这里利用flag去防止频繁操作按钮
html部分:
<el-button type="primary" :disabled="!isClick" @click="isClick&&handleLogin()">登录</el-button>
script部分:
<script>
export default {
data() {
return {
isClick: true
}
},
methods: {
handleLogin() {
this.isClick = false
this.$http( //发送异步请求
// 请求相关
).then(() => {
this.isClick = true//请求完成时恢复事件绑定
})
}
}
}
</script>