Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
{this.props.PROP}在类名内。-ReactJS_Reactjs_Ecmascript 6 - Fatal编程技术网

{this.props.PROP}在类名内。-ReactJS

{this.props.PROP}在类名内。-ReactJS,reactjs,ecmascript-6,Reactjs,Ecmascript 6,我有下一个代码: <div class="panel panel-default"> <div class="panel-heading"> <h3 class="panel-title text-center" style={STYLES.titleStyle}><span class="glyphicon glyphicon-align-justify"></span> {this.props.title}&

我有下一个代码:

<div class="panel panel-default">
    <div class="panel-heading">
        <h3 class="panel-title text-center" style={STYLES.titleStyle}><span class="glyphicon glyphicon-align-justify"></span> {this.props.title}</h3>
    </div>
    <div class="panel-body" style={STYLES.contentStyle}>
        {children}
    </div>
</div>
我想试着这样做:参见glyphicon,第3行

<div class="panel panel-default">
    <div class="panel-heading">
        <h3 class="panel-title text-center" style={STYLES.titleStyle}><span class="glyphicon glyphicon-{this.props.MY-ICON}"></span> {this.props.title}</h3>
    </div>
    <div class="panel-body" style={STYLES.contentStyle}>
        {children}
    </div>
</div>

有没有办法做到这一点?。如果是的话。。。我怎么能这样做?谢谢。

在我使用图标的项目中,通常会有如下内容

下面是字体真棒,但只要将fa更改为glyphicons,它就会或多或少正确

export const Icon = (props: IconComponentProps) => {
    return <i className={ `fa fa-${props.icon} ${props.className}` } />;
};
你用它就像

<Icon icon="check" className="green" />
生产

如果您不想走那么远,只想让它在这种特定情况下工作,只需将myIcon道具传递给包含它的组件,并使用className={`glyphicon glyphicon-${this.props.myIcon}`}