zoukankan      html  css  js  c++  java
  • Fetch的使用

    import React,{ Component } from 'react';

    import {

        AppRegistry,

        ListView,

        Image,

        Text,

        StyleSheet,

        View,

        TouchableHighlight

    } from 'react-native';

    class SimpleNavigationApp extends Component{

        constructor(props){

            super(props);

            this.state = {

            title:'',

            slug:'',

            };

        }

        

        fetchData = ()=>{

            fetch('http://bbs.reactnative.cn/api/category/3')

            .then((response)=>response.json())

            .then((jsondata)=>{

                  this.setState({

                                title:jsondata.topics[0].title,

                                slug:jsondata.topics[0].slug,

                                })

                  })

            .catch((error)=>{

                   console.warn(error);

                   });

        };

        

        

        

      render() {

        return (

          <View style={{flex: 1, paddingTop: 22}}>

                <Text>

                    RN中文网头条文章:

                </Text>

                <Text>

                {this.state.title}

                </Text>

                <Text style={styles.bigblue}>

                {this.state.slug}

                </Text>

                <TouchableHighlight onPress={this.fetchData}>

                    <Text>提交</Text>

                </TouchableHighlight>

        </View>

        );

      }};

    const styles = StyleSheet.create({

                                     bigblue: {

                                     color: 'blue',

                                     fontWeight: 'bold',

                                     fontSize: 30,

                                     },

                                     red: {

                                     color: 'red',

                                     },

           });

    AppRegistry.registerComponent('SimpleNavigationApp', () => SimpleNavigationApp);

  • 相关阅读:
    bigint int smallint tinyint 我是个马大哈
    [转载]Jquery主要控件的取值、赋值,包括textbox,butt
    几个时间转化格式
    Linq 事务问题
    手机网页开发
    PM2.5口罩网上热销 防护作用有限“噱头”多
    按F5键刷新造成的数据重复提交
    Ajax中遇到的一点细节问题
    WCF(二)将WCF发布到WindowsService
    WCF(一)
  • 原文地址:https://www.cnblogs.com/zhoujiahong/p/6195774.html
Copyright © 2011-2022 走看看