kat*_*kat 23 css font-size inline-styles reactjs react-jsx
我想在ReactJS中做这样的事情:
var MyReactClass = React.createClass({
render: function() {
var myDivText = "Hello!";
var myFontSize = 6; //this is actually something more complicated, I'm calculating it on the fly
var divStyle = {
font-size: {fontSize + 'px !important;'},
};
return (<div style={divStyle}>{myDivText}</div>);
}
});
Run Code Online (Sandbox Code Playgroud)
问题是当我运行我的代码时出现这个错误:"模块构建失败:错误:解析错误:第5行:意外的令牌 - "显然,React不喜欢它font-size
有一个破折号.我该如何解决这个问题?有没有办法逃脱这个角色的反应?是否有一些不同的css属性反应更好,做同样的事情?
谢谢!
kat*_*kat 51
用fontSize
而不是font-size
解决方案是camelCase属性,通常包含破折号
http://facebook.github.io/react/tips/inline-styles.html
回答了我自己的问题:)
归档时间: |
|
查看次数: |
45790 次 |
最近记录: |