react - jsx/tsx设置style出现Types of property 'style' are incompatible. Type is not assignable to type 'CSSProperties'
2017-11-07T12:40:20Z||2017-11-10T08:58:07Z
这句话在tsx中提示错误:
<img alt="登录" style="vertical-align: center" width="20" height="20" src="a.png" />
原因是style要用对象表达式:
const style = {
verticalAlign: 'middle'
};
return (<img alt="登录" style={style} width="20" height="20" src="a.png" />);
或者更简洁的(注意是两层括号,最外层是jsx中嵌入JavaScript表达式,内层是JavaScript对象声明):
return (<img alt="登录" style={{ verticalAlign: 'middle'}} width="20" height="20" src="a.png" />);