【发布时间】:2018-10-04 18:52:38
【问题描述】:
我正在开发 Flickr 克隆,其中发送 axios GET 请求以在用户输入输入时检索照片。 我当前的路径返回未定义。对象的响应数组在哪里,所以我知道在哪里设置图像状态?谢谢!
搜索容器
import React, { Component } from 'react';
import TextField from 'material-ui/TextField';
import axios from 'axios';
class Search extends Component {
state = {
searchText: '',
images: []
}
onTextChange = (e) => {
this.setState({searchText: e.target.value}, () => {
axios.get('https://api.flickr.com/services/rest/?method=flickr.photos.search&api_key=ea72b9024308d54ba48382706bebb960&user_id=156981303%40N08&format=json&api_sig=f8866cedaa88ceccdfe1e1cf06dcaded')
.then(response => {
this.setState({images: response.???});
})
.catch(error => {
console.log(error)
});
});
}
render() {
console.log(this.state.images);
return (
<div>
<TextField
name="searchText"
value={this.state.searchText}
onChange={this.onTextChange}
floatingLabelText="Search for photos"
fullWidth={true}
/>
</div>
);
}
}
export default Search;
【问题讨论】:
标签: reactjs axios material-ui flickr