书法字典:https://www.shufadict.com

Axios 禁用缓存

Disable cache for Axios
1. set headers.Cache-Control = 'no cache' // not work for 0.19.x or later?
2. set timestamp in url parameter for each request(need backend work)

export const client = axios.create({
    baseURL: 'https://www.abc.com/api',
    timeout: 10000,
});

client.interceptors.request.use(
    config => {
        config.params = {...config.params, timestamp: Date.now()};
        config.headers.Authorize = localStorage.getItem('token') || '';
        return config
    },
    error => Promise.reject(error)
);

 

posted on 2020-08-12 17:06  翰墨小生  阅读(3621)  评论(0编辑  收藏  举报

导航

书法字典:https://www.shufadict.com