在使用Axios时,可以通过.async/await配合.then()来获取到Promise对象的返回值。例如:
async function getData() {
try {
const response = await Axios.get('https://api.github.com/users/octocat');
console.log(response.data);
return response.data;
} catch (error) {
console.error(error);
}
}
在使用getData()函数时,可以通过.then()获取返回的Promise对象的值:
getData().then(data => {
console.log(data);
})
这样就能正确获取到Axios返回的数据了,而不是[object Promise]。