React-Native之Fetch

2018-04-23  本文已影响0人  Coder_Answer
语法
fetch(参数)
.then(成功的回调函数)
.catch(失败的回调函数)
fetch(url, opts)
.then((response) => {
  /* 网络请求成功执行该回调函数,得到相应对象,通过response可以获取请求的数据 */
  /* 例如: json、text等等 */
  
  // return response.text();
  return response.json();
})
.then((responseData) => {
  /* 处理请求得到的数据 */

})
.catch((error) => {
  /* 网络请求失败执行该回调函数,得到错误信息 */

})
GET
POST
上一篇下一篇

猜你喜欢

热点阅读