首页 > 解决方案 > 在第二次尝试时让 Json 获取数据

问题描述

我正在第二次尝试获取我获取的 Json 数据。我必须刷新屏幕两次才能获取数据。想法?

var data = [];
    class Profiel extends Component {
      constructor(props) {

      }


      componentDidMount() {
      this.setState({fetching:true},()=>{
        this.getData().then(JsonData => data=JsonData).then(console.log(data));
      });

      }
      getData(){
        return fetch('https://Domain.eu.auth0.com/userinfo', {
          method: 'GET',
          headers: {
            Authorization: 'Bearer ' + token,
          },
        }).then((response) => {return response.json()})
      };

标签: javascriptjsonfetchstateauth0

解决方案


推荐阅读