javascript - 在第二次尝试时让 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()})
};
解决方案
推荐阅读
- r - 查找累积和,然后平均 R 中的值
- javascript - Datepicker 默认日期应该是昨天,并且总是从月份的第一天开始
- azure - 为什么在 Azure 门户上禁用“创建主题”选项?
- javascript - 未捕获的类型错误:无法读取 vueJs 中未定义的属性“长度”(AmChart 实现)
- android - 使用 setOnTouchListener 时 Webview 单击事件不起作用
- jenkins - 将 Jenkins 服务器从 Windows 迁移到 Linux 机器
- c# - 如何使用 api 从 gitlab repo 中提取 LFS 文件
- go - 如何更有效地返回数组
- javascript - Thingworx 甘特图错误为“TypeError:无法读取未定义的属性‘ActualDataRows’”
- javascript - 动态状态没有在反应中更新