vue中单个接口防抖
请求时候
// 判断是否关闭请求
cancelRequest() {
if (typeof this.source === 'function') {
this.source('终止请求')
}
},
async workflowRunResult(start) {
this.cancelRequest()
const params = {
id: this.id
}
await http.get(workflowRunResult, {
params: params,
// 必须对请求进行cancelToken设置
cancelToken: new axios.CancelToken(function(c) {
that.source = c
})
}).then(async(res) => {
// 成功后运行
}).finally(() => {
// 如果请求被取消则进入该方法判断
// if (axios.isCancel(thrown)) {
// console.log('终止请求');
// // console.log('Request canceled', thrown.message);
// } else {
// // handle error
// }
})
} finally {
}
},
终止请求方法