我正在嘗試創建一個動態串列,該串列取決于后端的專案數量;使用 axios get request,我能夠成功獲取資料。但是,當我嘗試將資料傳遞給函式或列印資料時,它不會列印出完整的資料。它只顯示專案標簽(1、0 ...),當我嘗試訪問資料本身時,它給了我未定義的資訊。
await axios.get("backend.com/category")
.then((res) => {
var result = [];
//console.log(res.data) shows the array with the actual data
for (var resdata in res.data) {
//console.log(resdata) shows only 1 and 0
result.push(
<div>
<ItemCards data = {resdata}></ItemCards>
</div>
);
}
以下是我收到的回復:
在映射之前記錄時:

在映射/ItemCards 函式中登錄時:

有誰知道如何解決這一問題?非常感謝您的寶貴時間。
uj5u.com熱心網友回復:
如果要將陣列資料作為道具傳遞給子組件,請將回圈更改為此:
for (var resdata of res.data) {
result.push(
<div>
<ItemCards data={resdata} />
</div>
);
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/485996.html
