react 动态操作className

一 、react 动态操作className

方案一:(改变style)

style={activeStoreId === item.id ? { background: '#f5f5f5' } : {}}

方案二:(直接操纵className)

className={activeStoreId === item.id ? "bgblue": "bgred"}

二、动态操作多个className

className={["text-24", activeStoreId === item.id?"h-300":"h-100"].join(' ')}

 

 

posted @ 2022-07-18 17:50  小呀小恐龙  阅读(1997)  评论(0)    收藏  举报