一. vue2写法:
<button :disabled="state" @click="clickbtn"></button>
//在data里面定义state初始值为false
data(){
return{
state:false
}
}
//在methods里面写点击事件
async clickbtn(){
if(this.state === false){
this.state = true;
await api.xxx() // 等api执行完后再更改状态。
this.state = false;
}
}
二. vue3 antUi写法:
1.在a-form中添加事件 @finish=“onFinish”
2.在a-form-item中添加submit按钮
3.onFinish事件
<FormItem>
<Row type="flex" justify="center">
<Button class="apply-btn" type="primary" html-type="submit">立即申请</Button>
</Row>
</FormItem>
// 定义state初始值为false
const timeState = ref<boolean>(false);
// 点击事件
const onFinish = async () => { // form验证成功提交
const params = {
// 请求参数
};
if (timeState.value === false) {
timeState.value = true;
await api.xxx(params);
timeState.value = false;
}
};