【问题标题】:No Result and No Error (reactjs)没有结果也没有错误(reactjs)
【发布时间】:2018-10-23 03:41:59
【问题描述】:

我想从此 API https://facebook.github.io/react-native/movies.json 获取数据 但没有得到数据,也没有错误!!

这是我的代码

import React, { Component } from "react";
class App extends Component {
  constructor() {
    super();
    this.state = {
      data: []
    };
  }
  componentDidMount() {
    fetch("https://facebook.github.io/react-native/movies.json")
      .then(Response => Response.json())
      .then(findresponse => {
        this.setState({
          data: findresponse.movies
        });
      });
  }
  render() {
    return (
      <div>
        {this.state.data.map((dynamicData, key) => (
          <div>
            <span>{dynamicData.releaseYear}</span>
          </div>
        ))}
      </div>
    );
  }
}
export default App;

请帮忙

【问题讨论】:

  • 代码正在运行。您期望的输出是什么?我能找到的唯一小问题是https:/facebook.github.io/react-native/movies.json 它应该是https://fa
  • 这是react-native 项目还是react 项目?

标签: reactjs api react-native react-router react-redux


【解决方案1】:

使用 axios 而不是 fetch。 我遇到了像你这样的错误。 获取是垃圾。它会导致很多问题。 试试 axios。

【讨论】:

    【解决方案2】:

    它正在工作。你能告诉我们你面临的错误是什么吗..

    【讨论】:

      【解决方案3】:
      fetch('https:/facebook.github.io/react-native/movies.json')
      

      您的网址无效,您忘记了 / - 它应该是 https://face...

      另一个小问题是你应该使用key prop:

          {this.state.data.map((dynamicData, key) => (
            <div key={key}>
              <span>{dynamicData.releaseYear}</span>
            </div>
          ))}
      

      【讨论】:

      • 如果您将https://facebook.github.io/react-native/movies.json 粘贴到浏览器窗口,您将获得 JSON 响应。有什么问题吗?
      猜你喜欢
      • 1970-01-01
      • 2021-05-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多