Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/439.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用axios从json url获取图像_Javascript_Json_Reactjs_Axios - Fatal编程技术网

Javascript 使用axios从json url获取图像

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={

我是React的初学者,尝试从中获取图像 我正在使用axios创建对api的获取请求,并在img wrapper div中显示图像,但图像没有被导入。我能够获取字符串数据。当我尝试在img src中使用map时,我得到了一个错误“期望一个赋值或函数调用,却看到了一个表达式”

反应

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}/>
)}