31468a37
Yang Xiaoxiao
source
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
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}))
}
|