- 在axios请求前禁用按钮,请求结束后再启用按钮
...
data() {
return {
submitting: false,
// 其他数据
}
},
methods: {
async submitForm() {
this.submitting = true // 禁用按钮
try {
// axios请求
} catch (error) {
// 错误处理
}
this.submitting = false // 启用按钮
}
}
- 在axios请求前清空提示信息,请求结束后再更新提示信息
{{ alertMessage }}
...
data() {
return {
alertType: null,
alertMessage: null,
// 其他数据
}
},
methods: {
async submitForm() {
this.alertType = null // 清空提示类型
this.alertMessage = null // 清空提示信息
try {
// axios请求
this.alertType = 'success'
this.alertMessage = '提交成功'
} catch (error) {
// 错误处理
this.alertType = 'error'
this.alertMessage = '提交失败,请重试'
}
}
}