react 的className动态修改

https://blog.csdn.net/suwyer/article/details/81481507(copy)

<div style={{display: (index===this.state.currentIndex) ? "block" : "none"}}>此标签是否隐藏</div>
<div style={{display: (index===this.state.currentIndex) ? "block" : "none", color:"red"}}>此标签是否隐藏</div>
<div className={index===this.state.currentIndex?"active":null}>此标签是否选中</div>
<div className={`container tab ${index===this.state.currentIndex?"active":null}`}>此标签是否选中</div>

最好一种推荐使用

posted @ 2019-06-05 11:21  ThisCall  阅读(4487)  评论(0编辑  收藏  举报