在ReactJs的for循环内使用image标签

时间:2019-02-01 15:59:11

标签: reactjs

我有一个数组,其中包含一组图像名称。我可以使用console.log打印所有图像,但是不幸的是,当我尝试<img/>时,它无法查看图像。

   for (let index = 0; index < array.length; index++) {
   const element = array[index];
   console.log(element)
     }

console.log(element)

的输出
DSC_0000038.jpg 
DSC_0000040.jpg 
DSC_0000039.jpg 
DSC_0000047.jpg 
DSC_0000045.jpg 
DSC_0000049.jpg 
DSC_0000042.jpg 
DSC_0000041.jpg

如何解决我的问题?

1 个答案:

答案 0 :(得分:1)

执行以下操作:

r=["foo","bar"]
origStr = f'I went to the {r[0]} to get {r[1]}'

origStr
Out[21]: 'I went to the foo to get bar'