useCache:false ,
ttl:60000 ,
maxCache:0 ,
validateCache: (url, options) => { return options.method.toLowerCase() === 'get' },
github地址
import {extend} from 'umi-request';
const request = extend({
errorHandler,
prefix: '/rest',
});
request.interceptors.request.use((url: string, options: any) => {
const token = localStorage.getItem('auth');
const headers = {
Accept: 'application/json',
Authorization: '',
};
if (token) {
headers.Authorization = token;
return {
url: `${basicUrl}${url}`,
options: {
interceptors: true,
headers,
useCache: true,
ttl: 60000,
maxCache: 0,
timeout:5000,
...options,
},
};
}
return {
url: `${basicUrl}${url}`,
options: {...options, interceptors: true,},
};
});