当我将console.log(3);
添加到下面的类时,它会抛出错误
class AlbumList extends Component {
state ={ albums: [] };
console.log(3);
componentWillMount() {
console.log(4);
axios.get('https://rallycoding.herokuapp.com/api/music_albums')
.then(response => this.setState({ albums: response.data }));
}
renderAlbums() {
console.log(5);
return this.state.albums.map(
album => <AlbumDetail key={album.title} myAlbum={album} />
);
}
render() {
console.log(6);
return (
<View>
{this.renderAlbums()}
</View>
);
}
}
答案 0 :(得分:0)
您需要将console.log(3)
放在任何方法中,例如您可以将其添加到componentDidMount()
componentDidMount() {
console.log(3)
}