我正在使用 nextjs,我正在嘗試獲取影像串列,我想添加類(使用 if else 條件)我想要甚至發布我想添加類名“mt10”
這是我的代碼
{this.state.books.map((book, index) => {
const isEven = index % 2 === 0
console.log('data is ' isEven);
return
(
<div className="col-md-4 {isEven } forbcol">
<div className="bookimg">
<img src="img/forbes.png" />
</div>
</div>
)
})}
uj5u.com熱心網友回復:
{this.state.books.map((book, index) => {
return
(
<div className={`col-md-4 ${index % 2 === 0 ? 'mt10' : '' } forbcol`}>
<div className="bookimg">
<img src="img/forbes.png" />
</div>
</div>
)
})}
uj5u.com熱心網友回復:
{this.state.books.map((book, index) => {
const isEven = index % 2 === 0
console.log('data is ' isEven);
const style = {`col-md-4 ${isEven } forbcol`}
return
(
<div className={style}>
<div className="bookimg">
<img src="img/forbes.png" />
</div>
</div>
)
})}
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/495639.html
標籤:javascript 反应 下一个.js
