@action getBaseInfo = async() => { let baseInfo; try { baseInfo = await getBaseInfo(this.id); if (baseInfo) { this.baseInfo = baseInfo; // 發起請求後拿到 promise const visitedPromise = getVisitedCount(this.id); const subscribedPromise = getSubscribedCount(this.id); const connectionPromise = getConnection(this.id); // 等待 promise 返回再進行操做 baseInfo.visitedCount = await visitedPromise; baseInfo.subscribedCount = await subscribedPromise; const connection = await connectionPromise; baseInfo.phoneNumber = connection.phoneNumber; baseInfo.email = connection.email; this.baseInfo = baseInfo; } } catch (e) { throwError(e); } };
多個請求的時候不使用 await,而是拿到請求的 promise,將 await 用在 promise 上,等待 promise 返回promise