【发布时间】:2021-11-30 02:35:30
【问题描述】:
我是 nodejs 的新手,所以我很难解决一些问题,提前谢谢你。
这是我的.../src/http/index.ts 文件
import axios from 'axios'
export const API_URL = `http://localhost:5000/api`
const $api = axios.create({
withCredentials: true,
baseURL: API_URL
})
$api.interceptors.request.use((config) => {
config.headers.Authorization= `Bearer ${localStorage.getItem('token')}`
return config
})
export default $api
这里的config.headers 带有下划线,ts 告诉我
Object is possibly 'undefined'. TS2532
12 |
13 | $api.interceptors.request.use((config) => {
14 | config.headers.Authorization= `Bearer ${localStorage.getItem('token')}`
| ^
15 | return config
16 | })
17 |
我只是想了这么久,不知道是什么问题
AxiosRequestConfig.headers?: 记录
【问题讨论】:
标签: node.js typescript http axios interceptor