javascript - 异步/等待调用功能的最佳方式?
问题描述
我想知道是否可以从第二次或第三次通话中删除一些等待。
async componentDidMount() {
try {
let response = await this.CollectionManager.GetAllCollections();
if(!response.error) {
this.setState({collections: response.data});
}
} catch (e) {
this.notify("Error can't connect with the server.");
}
}
async GetAllCollections() {
try {
return await this.httpClient.Get(this.api_url);
} catch (e) {
}
}
async Get (url) {
try {
return this.Response(await Axios.get(this._apiUrl + url));
} catch (e) {
}
}
我在互联网上找不到更多示例。
解决方案
我认为您需要从中删除等待componentDidMount
并阅读这篇文章也许可以帮助你https://javascript.info/async-await
推荐阅读
- ssis - (Azure) 数据工厂到数据仓库 - 动态命名登陆表和架构
- hibernate - ExampleMatcher.withIgnorePath 正在获取被忽略的属性路径
- amazon-web-services - 使用 s3-dist-cp 跨 AWS 账户复制 S3 文件
- c# - WinForms 设计器中出现错误“找到的程序集的清单定义与程序集引用不匹配”
- ios - Xcode 10:无法附加数据库错误
- javascript - 访问组件内的模板变量
- php - 将数字除以 2 个多维数组
- java - 如何使用 html 模板在 java 电子邮件中添加图像
- typescript - 将 Vue.js 导入打字稿文件的最简单方法是什么?
- javascript - Node.js Express.js MongoDB:route.post() 需要回调函数,但得到了 [object Undefined]