作者:素子花开365 | 来源:互联网 | 2023-01-13 17:54
嗨,当我在前端有条件输出时,是否有可能else if ()
发表声明?
当前代码如下:
{this.props.contentComponentData.typeOf === 1
&&
}
提前致谢
1> Nicholas Tow..:
您可以使用条件运算符来生成if/else表达式:
{someCOndition=== true ? (
) : (
)}
如果你想要一个if/elseif/else,你可以将多个条件组合在一起:
{someCOndition=== true ? (
) : someOtherCOndition=== true ? (
) : (
)}
这些东西可能很难阅读,所以你应该考虑使用正常的if和elses将这些代码拉到你的return语句之上:
let component;
if (someCOndition=== true) {
compOnent=
} else if (someOtherCOndition=== true) {
compOnent=
} else {
compOnent=
}
return (
{component}
);