您的位置:首页 > 理论基础 > 计算机网络

react native(八)加载网络数据 和chrome

2016-12-13 15:50 344 查看
进过一天的激烈战斗,UI界面终于成型,今天就开始加载网络数据

在官网上先看了一个短视频,发现了这个调试器chrome

1.好吧就先来说一说chrome(谷歌浏览器):

http://localhost:8081/debugger-ui打开这个网址

找到:视图-》开发者-》开发者工具 切到console目录

启动你的项目如是模拟器:command+D 选择Debug JS Remotely 就OK啦

这样就可以用console.log( )在你的项目中打印东西。





2.加载网络数据用fetch

//这是第二部分数据请求

componentDidMount() {

this.fetchData();

}

// 数据请求

fetchData() {

fetch(REQUEST_URL)

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

.then((responseData) => {

console.log(responseData)

})

.catch((error) => {

console.error(error);

});

}

哈哈 一段代码搞定
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  chrome native 网络 数据