美文网首页
3.RN网络编程fetch实操19-11-19

3.RN网络编程fetch实操19-11-19

作者: 你坤儿姐 | 来源:发表于2019-11-19 10:52 被阅读0次
    import React, { Component } from "react";
    import {
      View,
      Image,
      TouchableOpacity
    } from "react-native";
    import {
      Container,
      Content,
      Button,
      Text
    } from "native-base";
    
    class Help extends Component {
     constructor(props){
        super(props);
        this.state={
          showText:''
        }
      }
      render() {
        const userStore = this.props["domain.user"];
        const navigation = this.props.navigation;
        return (
          <Container>
              <Text style={Style.textRightStyle}>03782123232</Text>
              <Button onPress={()=>{
                      this.loadData();
              }}/>
            </Content>
          </Container>
        );
      }
      loadData(){
        fetch('http://web.juhe.cn:8080/constellation/getAll?consName=%E5%8F%8C%E5%AD%90%E5%BA%A7&type=today&key=46dd5530ed37e3aa19019edfa1d6de3d',
          // {method: 'GET',
          //   headers: {
          //     'Accept': 'application/json',
          //     'Authorization': 'Bearer .eyJzdWIiOiJhZG1pbiIsImF1dGgiOiJST0xFX0FETUlOLFJPTEVfVVNFUiIsImV4cCI6MTU3Nj.y3nixEZLmhayoY8x7Nr1VHNPOBAcBLK-8TJW7ZaxyCs-OjP3ltmifcLfQglBf1PnRxqJiVrcCG5G_ENxPjIzYg'
          //   }
          // }
          )
          .then(response => {
            if (response.ok){
              return response.text();
            }
            throw new Error('Network response was not ok.');
          })
          .then(responseText => {
            this.setState({
              showText: responseText
            })
          })
          .catch(e =>{
            this.setState({
              showText:e.toString()
            })
          })
      }
    }
    
    Help.navigationOptions =({ navigation }) => ( {
      title: 'Help',
      headerLeft: (
          <View style={{ marginLeft: 15 }}>
            <TouchableOpacity onPress={() => navigation.goBack()}>
              <Image source={require('../../assets/images/profile_pic/baseline-chevron_left_back.png')}/>
            </TouchableOpacity>
          </View> ),
      headerTitleStyle: {
        alignSelf: "center",
        textAlign: "center",
        flex: 1
      },
    });
    export default Help;
    

    相关文章

      网友评论

          本文标题:3.RN网络编程fetch实操19-11-19

          本文链接:https://www.haomeiwen.com/subject/jjkwictx.html