2 回答
TA贡献1841条经验 获得超3个赞
async意味着你的函数返回一个承诺。这是一个基本事实
const get = async () => {
const res = await axios.get(
"https://www.themealdb.com/api/json/v1/1/list.php?i=list"
);
return res;
};
get().then(result => {
console.log(result);
})
阅读相关内容: https: //javascript.info/async-await
但是在这种情况下你不需要,async因为axios已经返回了一个承诺
const get = () => axios.get("https://www.themealdb.com/api/json/v1/1/list.php?i=list")
TA贡献1842条经验 获得超21个赞
你应该返回 res.data
import axios from 'axios';
const get = async () => {
const res = await axios.get(
"https://www.themealdb.com/api/json/v1/1/list.php?i=list"
);
return res.data;
};
const print = async()=>{
const resp = await get();
console.log(resp);
}
print();
添加回答
举报