javascript - React-Native:axios 收到 500 内部服务器错误

标签 javascript http react-native get expo

代码应该在控制台中返回专辑对象列表,但没有返回它,而是收到 500 内部服务器错误。

错误:enter image description here

import React, { Component } from 'react';
import { Text, View } from 'react-native';
import axios from 'axios';

class AlbumList extends Component {

  componentWillMount() {
      axios.get('https://rallycoding.herokuapp.com/api/music_albums')
        .then(function(response){
          console.log(response);
        })
  }

  render(){
    return(
      <View>
        <Text> Albums ! </Text>
      </View>
    );
  }
}

export default AlbumList;

最佳答案

你能试试这个吗

axios({
    method: 'get',
    url: 'https://rallycoding.herokuapp.com/api/music_albums',
    }).then(response => {
      console.log(response.data);

    })
    .catch((error) => {
      console.log(error);
    });

关于javascript - React-Native:axios 收到 500 内部服务器错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51783788/

相关文章:

java - 当没有创建资源时,我应该为 POST 返回什么 HTTP 状态代码?

react-native - 尝试重置导航会引发错误

javascript - 不完全由 Angular 表达式组成的正则表达式匹配字符串

javascript - 错误 : querySrv ENOTFOUND _mongodb. _tcp.cluster0.kspub.mongodb.net

javascript - 时刻JS ("Must to show days in next week")

javascript - 如何在javascript中过滤数组内的嵌套对象

ios - React Native(iOS) Module AppRegistry 不是注册的可调用模块(调用runApplication)

javascript - 获取选择的元素类型

http - 用户代理字符串可以有多大?

c# - 简单的 C# Http/TCP 服务器