const imageHtml = imageDescription.map((article, index) => {
return (
<div style={{ backgroundImage: "url(/images/Large/" + article.imagePath + ".jpg)" }}>
</div>
)
})
我正在做一个滑块的事情,但我遇到了一个问题,如何应用特定文章的左侧属性?例如,仅对索引1应用left = 20px?
你可以给其余的左= 0:
<div style={{backgroundImage: ..., left: (index === 1 ? 20 : 0)}} />
或者,如果您不想包括它:
<div style={Object.assign({backgroundImage: ...}, (index === 1 ? {left: 20} : {}))} />