Internet Explorer 缓存 http 请求。我不想手动向每个单独的函数添加 header ,而是想做这样的事情
axios.interceptors.request.use((config): AxiosRequestConfig => {
return addNoCachingHeader(config);
});
和
const addNoCachingHeader = (config: AxiosRequestConfig): AxiosRequestConfig => {
return { ...config, headers: { ...config.headers, Pragma: "no-cache"} };
};
是否有一种简单的方法可以阻止 IE 缓存请求,而无需返回整个应用程序并向每个单独的请求添加 header ?
最佳答案
我认为在这里使用通用客户端方法会更好。
const client = axios.create({
baseURL,
timeout: 5000,
responseType: 'json',
headers: { Pragma: "no-cache" },
});
并在其他地方使用导入客户端并调用client.get
或client.post
如果您想在某个时候覆盖 header ,请将其设为函数
const client = (headers) => axios.create({
baseURL,
timeout: 5000,
responseType: 'json',
headers,
});
并用作client({ Pragma: 'no-cache' }).get(...)
关于javascript - 如何给每个请求添加拦截器,让ie不缓存请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50456542/