-1

我有一个具有以下值的 userBalance 承诺对象:

> userBalance
Promise {
'100000000000000000',
domain:
 Domain {
   domain: null,
   _events:
    { removeListener: [Function: updateExceptionCapture],
      newListener: [Function: updateExceptionCapture],
      error: [Function: debugDomainError] },
   _eventsCount: 3,
   _maxListeners: undefined,
   members: [] } }

问题是,我无法从中得到 100000000000000000。有办法吗?

4

1 回答 1

3

获得 promise 的解析值的唯一方法(即使它已经被解析)是使用 promise,通过thenor await

userBalance.then(value => {
    // ...use `value`; note this will be called asynchronously
});

或在一个async函数中:

const value = await userBalance; // Note this will be asynchronous

在这两种情况下,加上错误处理,除非您将生成的承诺传递给其他处理它的东西。

于 2018-06-14T07:39:21.673 回答