如何将图像从JSON获取到React?

时间:2019-07-19 08:30:57

标签: react-native

如何将图像从JSON检索到React中?

我为图像"icon1":"./assets/tab.png"设置了json。像这样App.js一样,将此json导入到import myjson from './tinyone.json'中。之后,我尝试下面的代码。我收到<h3><p>,但没有收到<img>。怎么做?

// my.json
{
"header":"Tinyone Features",
"description":"Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry'sd dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.",
"features1":[{
    "icon1":"./assets/tab.png",
    "header1":"Fully Responsive",
    "desc1":"Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry'sd dummy text ever since the 1500s."
}



// App.js
<div className="App">
   <img src={myjson.features1[0].icon1} />
   <h3>{myjson.features1[0].header1}</h3>
   <p>{myjson.features1[0].desc1}</p>
</div>

我想在网页上显示图片,但不显示。

0 个答案:

没有答案