【问题标题】:axios interceptors and eslintaxios 拦截器和 eslint
【发布时间】:2022-11-09 17:01:55
【问题描述】:
axios.interceptors.request.use((config) => {
  config.headers = { ...config.headers, customHeader: 'ABC' };
  return config;
});

ESLINT 错误:

错误分配给函数参数'config'的属性 无参数重新分配

如何正确分配我的 customHeader 配置?

【问题讨论】:

    标签: javascript axios eslint


    【解决方案1】:

    尝试

    axios.interceptors.request.use((config) => {
      return {
        ...config, 
        headers: {...config.headers, customHeader: 'ABC" }
      };
    });
    

    【讨论】:

      【解决方案2】:

      尝试

      axios.interceptors.request.use((config) => {
        const newConfig = config;
        newConfig.headers.customHeader= "ABC"
        return newConfig;
      });
      

      【讨论】:

        猜你喜欢
        • 2018-11-27
        • 2019-04-12
        • 2016-06-24
        • 2019-06-26
        • 2023-04-06
        • 2021-05-10
        • 1970-01-01
        • 2020-01-19
        • 2018-01-20
        相关资源
        最近更新 更多