Javascript 使用axios从json url获取图像
我是React的初学者,尝试从中获取图像 我正在使用axios创建对api的获取请求,并在img wrapper div中显示图像,但图像没有被导入。我能够获取字符串数据。当我尝试在img src中使用map时,我得到了一个错误“期望一个赋值或函数调用,却看到了一个表达式” 反应Javascript 使用axios从json url获取图像,javascript,json,reactjs,axios,Javascript,Json,Reactjs,Axios,我是React的初学者,尝试从中获取图像 我正在使用axios创建对api的获取请求,并在img wrapper div中显示图像,但图像没有被导入。我能够获取字符串数据。当我尝试在img src中使用map时,我得到了一个错误“期望一个赋值或函数调用,却看到了一个表达式” 反应 class form extends Component{ constructor(props){ super(props); this.state={
class form extends Component{
constructor(props){
super(props);
this.state={
answer:'',
persons:[]
}
this.handleChange=this.handleChange.bind(this);
this.handleSubmit=this.handleSubmit.bind(this);
}
componentDidMount(){
axios.get('https://api.randomuser.me')
.then(res=>{
this.setState({ persons: res.data.results });
})
}
render(){
return (
<div>
<section className="login">
<div className="loginContainer">
<div className="heading">
</div>
<div className="img-wrapper">
<img src={this.state.persons.map(person=>{person.picture.large})}/>
</div>
i使用
Array.map()
创建this.state.persons
并渲染img
s
{this.state.persons.map(person =>
<img src={person.picture.large}/>
)}
{this.state.persons.map(person=>
)}
{this.state.persons.map(person =>
<img src={person.picture.large}/>
)}