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

进过一天的激烈战斗,UI界面终于成型,今天就开始加载网络数据
在官网上先看了一个短视频,发现了这个调试器chrome

1.好吧就先来说一说chrome(谷歌浏览器):
http://localhost:8081/debugger-ui打开这个网址
找到:视图-》开发者-》开发者工具 切到console目录
启动你的项目如是模拟器:command+D 选择Debug JS Remotely 就OK啦
这样就可以用console.log( )在你的项目中打印东西。

react native(八)加载网络数据 和chrome_第1张图片

2.加载网络数据用fetch
//这是第二部分数据请求
componentDidMount() {
this.fetchData();
}
// 数据请求
fetchData() {
fetch(REQUEST_URL)
.then((response) => response.json())
.then((responseData) => {
console.log(responseData)
})
.catch((error) => {
console.error(error);
});

}
哈哈 一段代码搞定

你可能感兴趣的:(React,Native,iOS)