【发布时间】:2021-12-14 07:46:59
【问题描述】:
我正在尝试根据代码显示 3 种不同的样式,但我无法使用三元表达式来实现。我找到了一些解决方案here,但仍然遇到了一些问题。
以下条件是我想做的:
<div className={styles.extraContainer}>
{
(() => {
if (!opened && !followed )
<div id={styles.themeBox}><p>+10</p></div> //show this box
else if (opened && !followed)
<img src={arrowDownIcon} alt="" style={{height:'1.2em',
marginLRight:'10px', width:'auto', objectFit:'contain'}} /> //show this icon
else
"" //show nothing
})()
}
</div>
因为当我尝试以下代码时,我收到 Do not nest ternary expressions. 错误。
{!opened && !followed ? <div id={styles.themeBox}><p>+10</p></div> : (opened && !followed ? <img src={arrowDownIcon} alt="" style={{height:'1.2em', marginLRight:'10px', width:'auto', objectFit:'contain'}} /> : ""}
【问题讨论】:
标签: javascript reactjs jsx