在 JSX 中,如何将 className 设置为 string + {prop} [英] In JSX how do I set a className as string + {prop}
本文介绍了在 JSX 中,如何将 className 设置为 string + {prop}的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我对 React 有点陌生,并试图将 className 设置为 string + prop.但我不确定该怎么做以及这是否是最佳做法.
I'm a bit new to React and trying to set a className as string + prop. But I'm not sure how to do it and whether that is the best practice.
所以我正在尝试做的,但显然没有用,是这样的:
So what I'm trying to do, and it's obviously not working, is this:
<a data-featherlight='string' + {this.props.data.imageUrl}>
我将如何写这篇文章?
推荐答案
可以使用字符串连接
<a data-featherlight={'string' + this.props.data.imageUrl}>
或使用模板字符串
ES2015 新特性
or use Template strings
new ES2015 feature
<a data-featherlight={ `string${this.props.data.imageUrl}` }>
这篇关于在 JSX 中,如何将 className 设置为 string + {prop}的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文