我有一个基于这样的承诺的js代码:
fetch(answerUrl, bodyRequest)
.then(response => response.json())
.then(data => {
data['status'] === 200 ? indicateSuccess() : indicateError();
})
.catch(err => {console.log(err)});
如果我想将其更改为异步/等待,这是正确的方法吗?
async function answerUrlData(answerUrl, bodyRequest) {
try {
const response = await fecth(answerUrl, bodyRequest)
const data = await response.json()
return data['status'] === 200 ? indicateSuccess() : indicateError();
} catch(err) {
console.log(err)
}
}
提前谢谢