我正在尝试在 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>);
}
});
问题是当我运行我的代码时出现这个错误:
“模块构建失败:错误:解析错误:第 5 行:意外的 token -”
显然,React 不喜欢 font-size
中有破折号。我该如何解决这个问题?有什么方法可以逃避那个 Angular 色使用react吗?是否有一些不同的 css 属性更喜欢做同样的事情?
谢谢!
最佳答案
使用fontSize
代替font-size
解决方案是使用通常包含破折号的 camelCase 属性
http://facebook.github.io/react/tips/inline-styles.html
回答了我自己的问题:)
关于css - 使用 ReactJS 生成内联字体大小样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26759819/