Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/26.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.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
Reactjs React componentDidMount不显示axios响应_Reactjs_Axios - Fatal编程技术网

Reactjs React componentDidMount不显示axios响应

Reactjs React componentDidMount不显示axios响应,reactjs,axios,Reactjs,Axios,我有React组件RandomQouteMachine,它应该从提供的URL获取响应并在页面上显示。我没有看到显示响应。调试“是否安装了组件?”消息也丢失 import React, { Component } from 'react'; import axios from 'axios'; lass RandomQouteMachine extends Component { constructor(props) { super(props); this.state =

我有React组件RandomQouteMachine,它应该从提供的URL获取响应并在页面上显示。我没有看到显示响应。调试“是否安装了组件?”消息也丢失

import React, { Component } from 'react';
import axios from 'axios'; 
lass RandomQouteMachine extends Component {
  constructor(props) {
    super(props);

    this.state = {
      data: ""
    };    
  }

  componenetDidMount() {
    console.log('Did component mount ?');
    axios.get('https://api.icndb.com/jokes/random')
      .then((res) => {       
        this.setState({data:res.value.joke});
      })

  }
  render() {
    return (
      <div>
        Here it is:
      {this.state.data}
      </div>
    );
  }
}

export default RandomQouteMachine;
import React,{Component}来自'React';
从“axios”导入axios;
lass RandomQouteMachine扩展组件{
建造师(道具){
超级(道具);
此.state={
数据:“”
};    
}
componenetDidMount(){
log('Did component mount?');
axios.get()https://api.icndb.com/jokes/random')
.然后((res)=>{
this.setState({data:res.value.joke});
})
}
render(){
返回(
这是:
{this.state.data}
);
}
}
导出默认随机QouteMachine;
我是否正确使用了componenetDidMount()?我只能在这里看到:“显示在第

页上,请检查拼写

componenetDidMount!==componentDidMount

检查拼写


componenetDidMount!==组件安装

太好了,非常感谢;)也许您还可以帮助解决TypeError:无法读取未定义的属性“笑话”。Axios response应该会告诉我您正在尝试从res.value获取数据。如果您查看axios网站上的文档,您需要从res.dataGreat获取信息,非常感谢;)也许您还可以帮助解决TypeError:无法读取未定义的属性“笑话”。Axios response应该会告诉我您正在尝试从res.value获取数据。如果您查看axios网站上的文档,则需要从res.data获取信息