下邊我簡單的寫一下想法function demo(){let data=[];fetch(xxx).then((res)=>{ data.push(res);})return data;}由于是異步請求,所以return的data依然是空數(shù)組,而非包含請求數(shù)據(jù)的數(shù)組。那有什么辦法在獲取數(shù)據(jù)后再return出去呢?
函數(shù)中包含一個fetch請求,如何把fetch請求的結(jié)果通過函數(shù)return出去
臨摹微笑
2018-11-14 10:15:26