如何获取配置csrftoken中的Cookie ?Axios.interceptors.request
Axios.interceptors.request.use(
config => {
if (
config.method === "post" ||
config.method === "put" ||
config.method === "delete"||
config.method === "get"
) {
}
if (Cookies.get('token')!==undefined) {
config.headers['Authorization']= 'Token '+Cookies.get('token');
}
// there I try to get the `csrftoken` in the Cookies, but I can not get.
if (Cookies.get('csrftoken')!==undefined) {
config.headers['x-csrftoken']= Cookies.get('csrftoken'); // 'CSRFToken'
}
return config;
},
error => {
return Promise.reject(error.data.error.message);
}
);
Run Code Online (Sandbox Code Playgroud)
在Axios.interceptors.request的配置中我无法获取 Cookies csrftoken: Cookies.get('csrftoken')。
我的 AxiosConfig 代码如下: …