【问题标题】:How to use fetch in react native如何在 React Native 中使用 fetch
【发布时间】:2020-10-13 07:29:12
【问题描述】:

我需要帮助,我想从 https://www.wired.com/category/security/ 获得最后 5 个帖子并使用 react native,但我不知道我该怎么做,任何人都可以帮助我,这对我来说非常重要。我想用 flatlist 在我的屏幕上显示,但我不知道该怎么做。

fetch(requestURL)
  .then((response) => response.json())
  .then((data) => {
    this.setState({
      data: data
    });
  })
  .catch((error) => console.log(error))
  .done();

【问题讨论】:

  • 您的基本 url 没有从 api 返回数据。此基本 url 没有响应来自 api 的数据
  • 我该如何解决?
  • 要解决此问题,您应该知道您请求的确切请求 URL。你从哪里得到这个 API 的 URL?

标签: reactjs react-native fetch react-native-fetch-blob


【解决方案1】:

希望这篇文章对你有所帮助

https://www.google.com/amp/s/aboutreact.com/react-native-http-networking/amp/ 这是关于如何使用 fetch 。

【讨论】:

  • 我知道这个库但我没有问这个,我想获取网站 api 但我不知道如何使用,例如 base url wired.com/category/security 是真的吗?
  • 是的,我已经更新了答案,请查看提到的链接
猜你喜欢
  • 1970-01-01
  • 2018-09-12
  • 2016-06-17
  • 2016-10-03
  • 1970-01-01
  • 1970-01-01
  • 2019-12-03
  • 2020-05-01
  • 2018-01-29
相关资源
最近更新 更多