export function executeCollectTask(data, token) {
return axios.post(apiUrls.executeCollectTask, {
...data,
}, {
cancelToken: token, // 标记要取消的请求
})
}
data(){
return {
source: null
}
}
methods: {
async $executeTask() {
try {
const CancelToken = axios.CancelToken
this.source = CancelToken.source()
const res = await executeCollectTask({ id: this.id }, this.source.token);
this.$message({
message: res.retDesc,
type: 'success',
duration: 1000
});
} catch (err) {
if (err.message) {
this.$message.success(err.message)
return
}
this.$message.error(err.retDesc || '执行任务出错');
}
},
// 取消请求
$cancel() {
this.source.cancel('已取消执行任务')
},
网友评论