Welcome to JiKe DevOps Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
270 views
in Technique[技术] by (71.8m points)

async/await怎么获取fetch的结果?

clipboard.png

clipboard.png

我把fetch封装到了fetchAsync函数里面,然后我最后想把返回的json数据给return出来,然后我在login函数里面可以直接获取result数据,但是发现result是一个promise,而不是一个json对象,请问该怎么获取fetch后的数据?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

Please log in or register to answer this question.

1 Answer

0 votes
by (71.8m points)

只要函数使用async/await,所有包含该函数的嵌套函数都得使用async/await.
下次代码也复制过来,贴图不好回复代码。

export const login = async() => {
    let result = await fetchAsync();
}

soonfy


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to JiKe DevOps Community for programmer and developer-Open, Learning and Share
...