我是本機反應的新手我正在構建一個書籍應用程式 UI,我有疑問
這是我的代碼
const data = [
{
id: "1",
title: "Name",
image: "https:/images", // i want to import images from my folder instead of fetching data from web
author: "Author Name",
},
<Image
style={{ width:200, height:200, top: -20, left: 65, resizeMode:"contain"}}
source={{ uri: item.image }} // ?? here
/>
我目前正在使用 uri for 匯入影像,但我想從我的資產檔案夾中匯入,但我不知道該怎么做,我為我的英語不好而道歉,請幫助我
uj5u.com熱心網友回復:
您應該使用require,應注意它必須獲得實際路徑(僅保留物件路徑,然后require在不允許的實作中動態保留)
{
id: "1",
title: "Name",
image: require("path/to/image"),
author: "Author Name",
}
...
<Image
style={{ width:200, height:200, top: -20, left: 65, resizeMode:"contain"}}
source={item.image}
/>
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/350349.html
上一篇:如何自定義textInput以確保用戶只能添加數字而不能添加逗號、點或其他符號?[復制]
下一篇:有沒有辦法將從APISAUCEAPI收到的回應存盤到異步存盤中作為快取,并在ReactNative的平面串列中顯示它
