gpt4 book ai didi

reactjs - 在 JSX 中,如何将 className 设置为 string + {prop}

转载 作者:行者123 更新时间:2023-12-03 12:54:33 25 4
gpt4 key购买 nike

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

所以我想做的,但显然不起作用,是:

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

我该如何写这个?

最佳答案

您可以使用字符串连接

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

或使用Template strings ES2015 新功能

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

关于reactjs - 在 JSX 中,如何将 className 设置为 string + {prop},我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35148695/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com