-
Notifications
You must be signed in to change notification settings - Fork 5
/
Util.js
47 lines (45 loc) · 982 Bytes
/
Util.js
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
41
42
43
44
45
46
47
'use strict'
import React,{Component} from 'react'
import {
PixelRatio,
Dimensions,
} from 'react-native'
/***
常用工具
***/
var Util={
//单位像素
pixel:1/PixelRatio.get(),
//屏幕的尺寸
size:{
width:Dimensions.get('window').width,
height:Dimensions.get('window').height,
},
//post请求(url:请求地址,data封装body,callback回调)
post(url,data,callback){
var feachOptions={
method:'POST',
headers:{
'Accept': 'application/json',
'Content-Type': 'application/json',
},
body:JSON.stringify(data),
};
fetch(url,feachOptions)
.then((response)=>response.text())
.then((responseText)=>{
callback&&callback(JSON.parse(responseText));
}).catch((error)=>{
console.log('error='+error);
});
},
//get请求
get(url,callback){
fetch(url)
.then((response)=>response.text())
.then((respnseText)=>{
callback(JSON.parse(responseText));
});
}
}
export default Util;