Uncaught (in promise) Error: SyntaxError: Unexpected end of input
at Object._callee$ (webpack-internal:///./src/config/fetch.js:89:31)
at tryCatch (webpack-internal:///./node_modules/regenerator-runtime/runtime.js:62:40)
at Generator.invoke [as _invoke] (webpack-internal:///./node_modules/regenerator-runtime/runtime.js:296:22)
at Generator.prototype.(anonymous function) [as throw] (webpack-internal:///./node_modules/regenerator-runtime/runtime.js:114:21)
at step (webpack-internal:///./node_modules/babel-runtime/helpers/asyncToGenerator.js:17:30)
at eval (webpack-internal:///./node_modules/babel-runtime/helpers/asyncToGenerator.js:30:13)
at <anonymous>


import {
baseUrl
} from './env'
export default async(type = 'POST', url = '', data = {}, method = 'fetch') => {
type = type.toUpperCase();
url = baseUrl + url;
if (type == 'GET') {
let dataStr = ''; //数据拼接字符串
Object.keys(data).forEach(key => {
dataStr += key + '=' + data[key] + '&';
})
if (dataStr !== '') {
dataStr = dataStr.substr(0, dataStr.lastIndexOf('&'));
url = url + '?' + dataStr;
}
}
if (window.fetch && method == 'fetch') {
let requestConfig = {
credentials: 'include',
method: type,
headers: {
'Accept': 'application/json',
// 'Content-Type': 'application/json',
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
},
mode: "no-cors",
cache: "force-cache"
}
if (type == 'POST') {
Object.defineProperty(requestConfig, 'body', {
value: JSON.stringify(data)
})
}
try {
var response = await fetch(url, requestConfig);
var responseJson = await response.json();
} catch (error) {
throw new Error(error)
}
return responseJson
} else {
let requestObj;
if (window.XMLHttpRequest) {
requestObj = new XMLHttpRequest();
} else {
requestObj = new ActiveXObject;
}
let sendData = '';
if (type == 'POST') {
sendData = JSON.stringify(data);
}
requestObj.open(type, url, true);
requestObj.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
requestObj.send(sendData);
requestObj.onreadystatechange = () => {
if (requestObj.readyState == 4) {
if (requestObj.status == 200) {
let obj = requestObj.response
if (typeof obj !== 'object') {
obj = JSON.parse(obj);
}
return obj
} else {
throw new Error(requestObj)
}
}
}
}
}


把export default后面的async去掉或者返回一个Promise对象