【问题标题】: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;
});