import React, { Component } from 'react';
import { View, Text } from 'react-native';
import axios from 'axios';
class AlbumList extends Component {
state = { albums: [] } ;
componentWillMount(){
axios.get('https://rallycoding.herokuapp.com/api/music_albums')
.then(response => this.setState({ albums : response.data }));
}
renderAlbums(){
return this.state.albums.map(album => <Text>{albums.title}</Text>)
}
render(){
console.log(this.state);
return (
<View>
{this.renderAlbums()}
</View>
);
}
}
export default AlbumList;
它说"引用错误:找不到变量:专辑"它在工作后突然弹出,你知道发生了什么吗?
看起来与您的映射变量不匹配。在:
return this.state.albums.map(album => <Text>{albums.title}</Text>)
您使用 album
作为函数的变量名称,但随后引用albums.title
。