-
Notifications
You must be signed in to change notification settings - Fork 0
/
FecthText.js
79 lines (76 loc) · 1.97 KB
/
FecthText.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/**
* Created by Administrator on 2017/3/15 0015.
*/
import React, { Component } from 'react';
import {
Text,
View,
StyleSheet,
TouchableOpacity,
Image,
} from 'react-native';
import NavigatorBar from './NavigatorBar';
import HttpUtils from './HttpUtils';
export default class FecthText extends Component{
// 构造
constructor(props) {
super(props);
// 初始状态
this.state = {
result:''
};
}
onLoad(url){
HttpUtils.get(url)
.then(result=>{
this.setState({
result:JSON.stringify(result)
})
})
.catch(err=>{
this.setState({
result:JSON.stringify(err)
})
})
}
onSubmit(url,data){
HttpUtils.post(url,data)
.then(result=>{
this.setState({
result:JSON.stringify(result)
})
})
.catch(err=>{
this.setState({
result:JSON.stringify(err)
})
})
}
render(){
return (
<View style={styles.container} >
<NavigatorBar title='fecth的使用'/>
<Text style={styles.text}
onPress={()=>{
this.onLoad('http://app.95e.com/vm/getTagMaterials.aspx?v=1&i=21')
}}
>获取数据</Text>
<Text style={styles.text}
onPress={()=>{
this.onSubmit('http://app.95e.com/vm/getTagMaterials.aspx',{v:1,i:21})
}}
>提交数据 </Text>
<Text >返回的结果为:{this.state.result}</Text>
</View>
)
}
}
const styles=StyleSheet.create({
container:{
flex:1,
backgroundColor:'gray',
},
text:{
fontSize:40
}
})