React Native 应用程序不会获取 api 数据

React Native app won't fetch api data

我的 React Native 应用无法获取或获取 api 数据。它不会控制日志数据甚至错误。我试过使用 fetch 和 axios。

获取方法:

    export default class List extends React.Component {
      commponentDidMount() {
        fetch(URL)
        .then((response) => response.json())
        .then((responseData) => {
          console.log(responseData);
        })
        .catch(error => {
            console.log(error);
        });
      }
    }

axios 方法:

    export default class List extends React.Component {
      commponentDidMount() {
        axios.get(URL)
        .then(function (response) {
          console.log(response);
        })
        .catch(function (error) {
          console.log(error);
        });
      } 
    }

我不确定是什么问题,我在网上找不到解决方案。

请检查拼写功能 componentDidMount 并尝试下面的示例代码。

componentDidMount() {
  let URL = `https://...`;

  fetch(URL)
  .then(res => res.json())
  .then(res => {
      console.log('response:', res.data);
  });
}

希望对您有所帮助。