小编典典

在JSX中,如何将className设置为字符串+ {prop}

reactjs

我对React有点陌生,尝试将className设置为string + prop。但是我不确定该怎么做以及这是否是最佳实践。

所以我正在尝试做的,显然是行不通的,是这样的:

<a data-featherlight='string' + {this.props.data.imageUrl}>

我该如何写呢?


阅读 263

收藏
2020-07-22

共1个答案

小编典典

您可以使用字符串串联

<a data-featherlight={'string' + this.props.data.imageUrl}>

或使用Template strings新的ES2015功能

<a data-featherlight={ `string${this.props.data.imageUrl}` }>
2020-07-22