【问题标题】:Prepend String before Moment Timestamp在时刻时间戳之前添加字符串
【发布时间】:2020-01-12 22:44:03
【问题描述】:

clicked 状态为true 时,我正在使用 React 和 Material UI 来显示 Running check...。 否则,我将使用react-moment 显示时间戳。

 <Typography gutterBottom variant="caption">
   {this.state.clicked 
      ? "Running check..."
      : <Moment local format={dateFormat}>{lastCheckedDateTime}</Moment> }
 </Typography>

如何在时间戳前面加上 Last checked: 这样的字符串?

【问题讨论】:

    标签: javascript reactjs material-ui momentjs


    【解决方案1】:

    不知道Moment 组件呈现什么,但在它之前添加一个跨度或其他内容。如果 moment 组件是块元素,可能需要使用样式:

     <Typography gutterBottom variant="caption">
       {this.state.clicked 
          ? "Running check..."
          : (
            <>
              <span>Last checked: </span>
              <Moment local format={dateFormat}>{lastCheckedDateTime}</Moment>
            </>
          )
        }
     </Typography>
    

    【讨论】:

      猜你喜欢
      • 2018-11-30
      • 2016-11-28
      • 1970-01-01
      • 1970-01-01
      • 2020-11-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多