2 回答

TA貢獻(xiàn)1841條經(jīng)驗 獲得超3個贊
async意味著你的函數(shù)返回一個承諾。這是一個基本事實(shí)
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);
})
閱讀相關(guān)內(nèi)容: https: //javascript.info/async-await
但是在這種情況下你不需要,async因為axios已經(jīng)返回了一個承諾
const get = () => axios.get("https://www.themealdb.com/api/json/v1/1/list.php?i=list")

TA貢獻(xiàn)1842條經(jīng)驗 獲得超22個贊
你應(yīng)該返回 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();
添加回答
舉報