我目前正试图解决一个反应问题。
我希望能够将图标添加到名为SalesChannels的容器。 这里是代码的salesChannels页:(JSX)react - 将图标添加到组件内的头部
import React, { Component } from 'react';
import PageContent from 'components/PageContent';
import IBox from 'components/IBox';
export default class SalesChannelsPage extends Component {
constructor(props) {
super(props);
this.state = {
rows: []
}
}
render() {
return (
<PageContent header="Salgskanaler">
<IBox title="Salgskanaler">
</IBox>
</PageContent>
);
}
}
正如你所看到的,我已经添加了一个名为IBOX组件。这应该是可重复使用的 它看起来像这样:
import React, {Component} from 'react';
import IBoxTools from './IBoxTools'
export default class IBox extends Component {
render() {
return(
<div className="ibox">
<div className="ibox-title">
{this.props.title}
//this is where the icon should be rendered in the dom
</div>
<div className="ibox-content">
{this.props.children}
</div>
</div>
);
}
}
我也创造了另一个组件调用IBoxTools - 这包含实际的图标/“我”的标签:
import React, {Component} from 'react';
export default class IBoxTools extends Component {
render() {
let icon;
if(this.props.icon) {
icon = (
<a title={this.props.title}>
<i onClick={() => this.iconClicked()} className={`pull-right ${this.props.icon}`}></i>
</a>
);
}
return icon;
}
iconClicked() {
console.log('icon clicked')
}
}
那么我试图do是将多个图标添加到IBox标签内的SalesChannels页面,而不使IBox组件依赖于它。
我希望你能帮上忙。谢谢!
真棒,谢谢,它工作! :) – PatrickGoethe