我有一張看起來像這樣的地圖

我正在.map()嘗試將它們制作成這樣的影像:
{theLinks.map((item, indx) => (
<img key={indx} src={item.src} alt={item.label} />
))}
什么都沒有回傳,如果我弄亂了它,我可以獲得一個沒有有效來源的 img 回傳,并且 alt 是“未知的”。
uj5u.com熱心網友回復:
這行不通
export default function App() {
const theLinks = [
{ lable: "Daily Mix", src: "https://flif.info/example-images/fish.png" },
{ lable: "Legit", src: "https://flif.info/example-images/fish.png" },
{ lable: "SCL", src: "https://flif.info/example-images/fish.png" }
];
{theLinks.map((item, indx) => (
<img
style={{ width: "50%", border: "1px solid #ccc" }}
key={indx}
src={item.src}
alt={item.label}
/>
))}
}
這會起作用
export default function App() {
const theLinks = [
{ lable: "Daily Mix", src: "https://flif.info/example-images/fish.png" },
{ lable: "Legit", src: "https://flif.info/example-images/fish.png" },
{ lable: "SCL", src: "https://flif.info/example-images/fish.png" }
];
return (
<>
{theLinks.map((item, indx) => (
<img
style={{ width: "50%", border: "1px solid #ccc" }}
key={indx}
src={item.src}
alt={item.label}
/>
))}
;
</>
);
}
uj5u.com熱心網友回復:
嘗試這個
{theLinks.map((item, indx) => { return ( <img key={indx} src={item.src} alt={item.label} /> ); })}
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/486147.html
標籤:javascript 数组 反应
上一篇:如何傳遞變數的指標?
