import '../../config'; //全局路径 const commonUrl = global.constants.commonUrl // const commonUrl = 'http://192.168.10.219:4083' //解析json function parseJSON(response){ return response.json() } //检查请求状态 function checkStatus(response){ if(response.status >= 200 && response.status < 500){ return response } const error = new Error(response.statusText) error.response = response throw error } export default function request(options = {}){ const {data,url} = options options = {...options} delete options.url if(data){ delete options.data var formData_request = new FormData(); var key; for(key in data){ console.log(key) formData_request.append(key,data[key]) } options.body = formData_request } return fetch(commonUrl+url,options) .then(checkStatus) .then(parseJSON) .catch(err=>({err})) }