【发布时间】:2021-04-21 22:18:01
【问题描述】:
我在下面的函数中使用async/await
forgotPassword = async ({ variables }) => {
console.log(variables)
const url = `//url constructed`
console.log(url)
try {
const result: any = await fetch(url, {
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
mode: 'no-cors'
}
})
console.log('result fetched is -->', result)
return {
data: {
login: result.json()
}
}
} catch (err) {
this.setState({
error:
err?.response?.data?.error_description || err.message || strings.genericError
})
throw err
}
}
所以,在我这样做的结果中
result.json()
我收到如下回复:
Promise {<pending>}
__proto__: Promise
[[PromiseState]]: "fulfilled"
[[PromiseResult]]: Object
Status: "Successful"
Time: "1619013232787"
__proto__: Object
所以当我尝试这样做时
const status = result?.Status
然后它给了我undefined
如何获得响应?连承诺都兑现了。
【问题讨论】:
标签: javascript reactjs async-await promise