【发布时间】:2021-01-26 19:35:47
【问题描述】:
描述错误
我正在尝试发出要求将模式设置为no-cors 的请求。但是,我无法将 mode 传递到 Axios 配置中。我收到 TypeScript 错误 Object literal may only specify known properties, and 'mode' does not exist in type 'AxiosRequestConfig'
最终,我需要能够在sec-fetch-mode: no-cors 存在的地方提出请求。
const client: AxiosInstance = axios.create({
baseURL: apiBaseUrl,
withCredentials: true,
headers: {
'Content-Type': 'application/json; charset=utf-8',
},
adapter: cache.adapter,
});
无论是通过mode 还是其他财产,我都需要一种方法来提出这个请求。
const mediaUrl: string = await client
.get(paths.moment.media.getMediaUrl({ mediaId: media.id }), {
mode: 'no-cors'
})
.then(({ data }: { data: string }): string => data);
预期行为
能够针对特定请求将mode 设置为no-cors。
- Axios 0.20.0
- TypeScript 4.0.3
【问题讨论】:
标签: typescript axios cors