我正在尝试从API获得一些数据,但我正在接收承诺而不是数据
const fetchCoordinatesFromAdress = async (adress: any) => {
let response = {}
try {
response = await MapBoxAPIService.getCoordinatesFromAdress(adress)
} catch (e) {
console.warn(e)
}
return response.data
}
如果我控制台日志响应。data我得到数据,但我想返回数据然后它只返回promise
称其为await
或.then()
例子:
const data = await fetchCoordinatesFromAdress(address);
或
fetchCoordinatesFromAdress(address).then((data) => ...)
裁判:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise