【发布时间】:2020-11-26 09:40:51
【问题描述】:
我在这里遇到一个问题,即当我执行 Post API 并添加 console.log (responseJson) 时,数据会出现并且其内容是 (app_uid 和 app_number)。但是当我将API数据输入到dataApp[]状态并尝试console.log(this.state.dataApp)时,没有数据出现。
这是来自其 post API 函数的一段脚本:
onTask = (pro, tas) => {
fetch('https://bpm.***********.or.id/api/1.0/**********/cases/', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Accept-Encoding': 'gzip, deflate',
'Authorization': 'Bearer ' + this.state.token,
},
body: JSON.stringify({
'pro_uid': pro,
'tas_uid': tas,
}),
})
.then((response) => response.json())
.then((responseJson) => {
console.log(responseJson); //here the data appears
this.setState({
dataApp: responseJson,
});
console.log(this.state.dataApp); //but here does not appear any data
});
希望我能在这里找到解决方案,非常感谢。
【问题讨论】:
标签: json reactjs react-native api rest