我想在react js中使用值查询更改引导类...?
const Card = ({ item }) => {
return (
if (item.approval === "pending") {
<span className="badge badge-danger">{item.approval}</span>
} else if (item.approval === "Appropriate") {
<span className="badge badge-warning">{item.approval}</span>
} else if (item.approval === "approved") {
<span className="badge badge-success">{item.approval}</span>
}
)
}
export default Card
答案 0 :(得分:1)
您不能在return
中使用if语句。您需要在室外使用它。
您可以这样简单。
const Card = ({ item }) => {
let colorClassName = "badge-danger";
if (item.approval === "Appropriate") colorClassName = "badge-warning";
if (item.approval === "approved") colorClassName = "badge-success";
return (
<span className={`badge ${colorClassName}`}>{item.approval}</span>
)
}
export default Card