相关疑难解决方法(0)

如何在`Axios.interceptors.request`的配置中获取Cookies的`csrftoken`?

如何获取配置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 代码如下: …

javascript axios

6
推荐指数
1
解决办法
2万
查看次数

标签 统计

axios ×1

javascript ×1