字体颜色通过打字稿中的渲染反应



尝试通过反应组件内的变量设置字体颜色,但我的<span>给出了错误:

Type '{ style: "color:yellow"; }' is not assignable to type 'HTMLProps<HTMLSpanElement>'

黄色仅用于测试,最后我将替换为{颜色}。

import * as React from 'react';
export interface SkillListItemProps {
name: string
color: string
// Icons: 
}
interface SkillListItemState{
}
export class SkillListItem extends React.Component<SkillListItemProps,SkillListItemState>{
public render(): JSX.Element{
const {name, color} = this.props;
return (
<div className="SkillListItem"> 
<span style="color:yellow">{name}</span>
</div>
)
}
}

您必须使用一个对象,如下所示:

<span style={{color: "yellow"}}>{name}</span>

JSFiddle 演示:https://jsfiddle.net/4wcmcpv3/1/

最新更新