繁体   English   中英

异步/等待调用功能的最佳方式?

[英]The best way for async/await call funtion?

我想知道是否好或不从第二个或第三个电话中删除一些等待。

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删除 await

阅读这篇文章也许可以帮助你https://javascript.info/async-await

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM