今天在写代码的时候,发现一个问题:在一个标签里面已经有一个样式类,然后我还要添加一个样式类(此样式类是根据逻辑代码判断的)
首先来看下此需求:
- 一般给标签加样式类都是通过className设置属性
<div className='steps-action'>
</div>
- 如果有多个属性值,则可以像下面这样,注意:多个样式类之间需要用空格隔开
<div className='steps-action mgt-10 ant-table-footer'>
</div>
- 如果需要根据不同情况来展示的样式类,通常第一反应会这样,但这是不合法的。
<div className='steps-action' className={radioValue === '2' ? 'template-show' : 'template-hidden}>
</div>
- 解决上面不合法的问题,es6提出了模板字符串,因此:采用模板字符串解决,多个类之间用空格隔开
<div className={`steps-action ${radioValue === '2' ? 'template-show' : 'template-hidden'} `}>
{
isCheckFinish ?
<Tooltip title="正在检测实例,请稍等一分钟" placement="topLeft">
<Button type="primary" onClick={this.setCurrent.bind(this, 1)} disabled={true}>下一步</Button>
</Tooltip>
:
<Button type="primary" onClick={this.setCurrent.bind(this, 1)}>下一步</Button>
}
</div>