【发布时间】:2020-04-12 02:13:36
【问题描述】:
我将componentDidMount方法作为async使用并进行了一些操作,但是系统返回给我的是第一个条目的状态而不是异步工作。
async componentDidMount() {
await this.getCityList();
console.log(this.state.cities)
await this.currentLocation();
}
此时控制台日志变为空。但是,当我通常检查时,会观察到数据输入,但会在一段时间后出现。这同样适用于 currentloc 方法。这些方法从数据库中提取一些数据。
和城市功能:
getCityList() {
let link = "http://..../Cities";
fetch(link)
.then(response => response.json())
.then(res => {
this.setState({
cities: res,
})
})
.catch(error => console.warn(":::::::::", error));
}
【问题讨论】:
标签: c# react-native promise async-await