美文网首页
react-native fetch获取数据 方法详解

react-native fetch获取数据 方法详解

作者: 向前Hell | 来源:发表于2017-07-20 13:58 被阅读0次

    1.设一个request

    let myRequest = new Request(urlPath,{
                method:'POST',
                headers:{
                    'Content-Type': 'application/x-www-form-urlencoded',
                },
                body:params,
            });
    

    2.进行fetch调用

    fetch(myRequest)
                .then((response) => {return response.json();})
                .then((data) => {
                    this.state.dataList.push(data);
                    console.log(this.state.dataList[0]);
                    console.log(data);
                })
                .catch((error) => {
                    console.error(error);
                    Alert.alert("error!");
                });
    

    3.在React Native Debugger中看console.log输出

    获取到10条Object信息

    相关文章

      网友评论

          本文标题:react-native fetch获取数据 方法详解

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