尝试使用以下配置进行获取时出现 CORB 错误。在控制台上,它显示“跨域读取阻塞 (CORB) 阻止了具有 MIME 类型 application/json 的跨域响应 http://localhost:8080/api/xxxxx/xxxxx。有关详细信息,请参阅https://www.chromestatus.com/feature/5629709824032768 。
const {
token,
method = RequestMethod.GET,
headers: customHeaders = {},
body: requestBody,
data: requestData,
credentials = 'omit',
...customOptions
} = options
const headers: HeadersInit = new Headers({
Accept: 'application/json',
'Content-Type': 'application/json',
...customHeaders,
})
let body = requestBody
if (!body && requestData) {
body = typeof requestData !== 'string' ? JSON.stringify(requestData) : requestData
}
if (token) {
headers.set('Authorization', token)
}
const response = await fetch(endpoint, {
method,
headers,
body,
credentials,
mode: 'no-cors',
referrerPolicy: 'origin',
...customOptions,
})