接口重复请求,取消上一次请求

89 阅读1分钟

记录项目上问题 检测有效

import axios from 'axios';

const CancelToken = axios.CancelToken;
let source: any = CancelToken.source();
export async function queryDataSetField(id: string) {
    if (typeof source === 'function') {
        source('终止请求12');
    }
    const res = await get(`/api/xxx/xxx?fkDataSet=${id}`, {
        cancelToken: new axios.CancelToken(function executor(c) {
            source = c;
        }),
    });
    return res.data;
}