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

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

上级 b24abfed
......@@ -77,8 +77,12 @@ export const request = {
header: {
type: Object,
validator (value, params) {
params.header = value || {}
params.header['content-type'] = params.header['content-type'] || 'application/json'
const header = params.header = value || {}
if (params.method !== method.GET) {
if (Object.keys(header).filter(key => key.toLowerCase() === 'content-type')) {
header['Content-Type'] = 'application/json'
}
}
}
},
dataType: {
......@@ -94,4 +98,4 @@ export const request = {
params.responseType = Object.values(responseType).indexOf(value) < 0 ? responseType.TEXT : value
}
}
}
}
......@@ -70,13 +70,6 @@ export function request ({
}
}
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) {
body = data
} else {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册