簡體   English   中英

React-Native動態圖像源?

[英]React-Native Dynamic Image Source?

我正在嘗試從JSON文件收集圖像源,但是每當我使用JSON對象源時,都會收到模塊錯誤。 有什么解決方法嗎?

JSON文件:

 {
   "Image": {"source": "./SourceFolder/ImageFile.png"}
 }

JS文件

 const file = require('./jason.json');
 var jason = JSON.stringify(file.Image);
 jason = JSON.parse(jason);

 <Image source={require(jason.source)} />

不支持動態需求。 您需要先獲取所有圖像,然后才能從引用中動態調用它們。

const images = {
  image1: require('some_file.png'),
}

<Image source={images["image1"]} />

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM