有条件地返回数据

我有这个功能:

 getFace(/* string */ face_name,/* int */ w,/* int */ h,/* int */ z) {
    const am = this.props.assetsManager;
    return {
      backgroundSize: 'contain',position: 'absolute',width: `${w}px`,height: `${h}px`,zIndex: z
  };

如果face_nameface2,我需要返回其他样式,即backroundColor: red

如何为条件语句添加条件?

csxha0506 回答:有条件地返回数据

您可以添加对象,然后根据以下条件将其添加到其中:

@JsonAnySetter
,

您可以使用函数添加条件类

class BookmarkArticle extends React.Component {
  getClassName(){
     let classname="";
     if (condition){
       return classname
     }else{
       return classname
     }
  }
  render(){
     return(
         <div className={this.getClassName}></div>
)}
}
本文链接:https://www.f2er.com/3037813.html

大家都在问