提交 8047c7f6 编写于 作者: Q qiang

fix: 解决 H5 端 GET 请求之前出现 OPTIONS 预检请求的问题

上级 b24abfed
...@@ -77,8 +77,12 @@ export const request = { ...@@ -77,8 +77,12 @@ export const request = {
header: { header: {
type: Object, type: Object,
validator (value, params) { validator (value, params) {
params.header = value || {} const header = params.header = value || {}
params.header['content-type'] = params.header['content-type'] || 'application/json' if (params.method !== method.GET) {
if (Object.keys(header).filter(key => key.toLowerCase() === 'content-type')) {
header['Content-Type'] = 'application/json'
}
}
} }
}, },
dataType: { dataType: {
......
...@@ -70,13 +70,6 @@ export function request ({ ...@@ -70,13 +70,6 @@ export function request ({
} }
} }
if (method !== 'GET') { if (method !== 'GET') {
if (!contentType) {
/**
* 跨域时部分服务器OPTION响应头Access-Control-Allow-Headers未包含Content-Type会请求失败
*/
header['Content-Type'] = 'application/json'
contentType = 'json'
}
if (typeof data === 'string' || data instanceof ArrayBuffer) { if (typeof data === 'string' || data instanceof ArrayBuffer) {
body = data body = data
} else { } else {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册