代码应该在控制台中返回专辑对象列表,但没有返回它,而是收到 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/