【发布时间】:2019-04-11 14:16:02
【问题描述】:
您好,我只想为 span 元素内的特定文本部分添加颜色。我将此文本作为道具传递给子组件,但我不知道该怎么做。
下面是代码,
switch(notification.type) {
case 'uploaded':
return (
<ListItem icon={<Svg/>} text={name +
'created item' + item.name} timestamp={timestamp}>
<div className="image">
<Image
width={70}
height={70}
item_id={item.id}
/>
</div>
</ListItem>
);
case 'comment':
return (
<ListItem icon={<Svg/>} text={name +
'commented item' + item.name} ref={this.comment_ref}
className="span" timestamp= {timestamp}>
</ListItem>
);
function ListItem(props) {
return (
<li className="item">
<div className="details">
{props.icon}
<span ref={props.ref} className={props.className}>
{props.text}
</span>
</div>
{props.children}
<Timestamp>{props.timestamp}</Timestamp>
</li>
);
}
从上面的代码中,每个案例都是将 text prop 传递给子组件 ListItem。在文本道具中,我希望名称和 item.name 为蓝色。 text={姓名 + '评论项目' + item.name} 我该怎么做?有人可以帮我解决这个问题。谢谢。
【问题讨论】: