实现有多个图片的遍历显示react

如图要想实现这个效果,首先这些图片是存储在一个数组中的,我们要取出图片然后遍历显示出来,可以如下显示:

render : ( text) => {
if ( text && text. length) {
const imgs = text. map(( item, index) =>
< div key= { index } style= {{ backgroundImage: `url( ${ item. mediaUrl } )` } } className= 'bg-cover teacher-medias' />
)
return < div style= {{ display: 'flex' } } > { imgs } </ div >
}
}

猜你喜欢

转载自blog.csdn.net/Alison_Z/article/details/80826945