再次尝试让Json提取数据

时间:2018-11-03 00:51:44

标签: javascript json fetch state auth0

我正在第二次尝试中获取我的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()})
      };

0 个答案:

没有答案
相关问题