【问题标题】:React return HTML with variable value反应返回带有变量值的 HTML
【发布时间】:2019-01-03 21:52:39
【问题描述】:

我想如何连接<i> 图标和电话号码并返回值

phone = () =>{
     let mapvalue = this.props.mapvalue
     return <i class='fa fa-map-marker'></i> mapvalue  
}

render() {
    return (
      {this.phone()}
    )
}

【问题讨论】:

  • span?像这样:return (&lt;span&gt;&lt;i class='fa fa-map-marker'&gt;&lt;/i&gt;{ mapvalue }&lt;/span&gt;);.

标签: javascript reactjs concatenation


【解决方案1】:

React.Fragment 仅适用于 React v.16 或更高版本

render () {
  return (
     <React.Fragment>
       <i class='fa fa-map-marker'></i>{this.props.mapvalue}
     </React.Fragment>
  )
}

【讨论】:

  • 或者,如果您使用 React v.16.2+,您可以使用 &lt;&gt;&lt;/&gt;
猜你喜欢
  • 1970-01-01
  • 2021-08-13
  • 1970-01-01
  • 2018-01-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-11-06
相关资源
最近更新 更多