【问题标题】:Hide element (Ionic React ts)隐藏元素(Ionic React ts)
【发布时间】:2020-12-28 05:22:09
【问题描述】:

我有

const Dashboard: React.FC<RouteComponentProps> = ({ history }) => {

  var random = 1;

  return (
    <React.Fragment>
      <IonTitle id="title">MyLittleClass Dashboard</IonTitle>
      <IonContent>
      </IonContent>
    </React.Fragment>
  );
};

export default Dashboard;

如果我的 var random 为 1,我如何隐藏 ID 为“title”的元素? .... 很简单,但我不明白如何引用我的元素。

【问题讨论】:

    标签: reactjs typescript ionic-framework ionic4 ionic-native


    【解决方案1】:

    使用条件显示,如:

    const Dashboard: React.FC<RouteComponentProps> = ({ history }) => {
    
      var random = 1;
    
      return (
        <React.Fragment>
          {random === 1 && <IonTitle id="title">MyLittleClass Dashboard</IonTitle>}
          <IonContent>
          </IonContent>
        </React.Fragment>
      );
    };
    
    export default Dashboard;
    
    

    在这种情况下,IonTitle 将仅在 random 等于数字 1 的情况下呈现。

    【讨论】:

      猜你喜欢
      • 2021-05-15
      • 1970-01-01
      • 2019-05-16
      • 1970-01-01
      • 2014-08-21
      • 2021-07-23
      • 2010-10-01
      • 1970-01-01
      相关资源
      最近更新 更多