【问题标题】:How to combine any values in the same component in to separate variable?如何将同一组件中的任何值组合成单独的变量?
【发布时间】:2020-06-05 02:41:38
【问题描述】:

我现在面临的问题是“有一些单独放置的生日值。”,例如value={this.props.year}value={this.props.month}value={this.props.day}。这些都放在不同的地方,我想要的只是将它们组合并包含在一个变量中或包含值之类的东西中。我是 React js 的新手。

【问题讨论】:

    标签: reactjs react-native react-redux


    【解决方案1】:

    这是一个非常简单的问题,有一个简单的解决方案,只需创建一个新变量并将它们全部连接在一起,为了更方便的流程,您可以在生命周期挂钩中完成,如下所示:

    componentWillMount(){
     this.setState({
     birthDate: this.props.month + '-' + this.props.day + '-' + this.props.year
     })
    {
    

    componentWillMount 函数是一个生命周期钩子,该函数将在组件挂载之前调用。这样您就可以访问带有日期的新变量。

    希望对你有帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-06-12
      • 1970-01-01
      • 2020-11-03
      • 1970-01-01
      • 1970-01-01
      • 2021-11-01
      • 1970-01-01
      相关资源
      最近更新 更多