当我使用以一个小字母开头的变量时,页面上什么也没有显示。如果我将变量名更改为大写(HelloWorld)开头,则页面将显示内容。
<script type="text/jsx">
var helloWorld = React.createClass({
render : function () {
return (
<div>
<h1>Hello World</h1>
</div>
);
}
});
React.render(<helloWorld/> , document.body);
</script>有人能告诉我为什么会这样吗?
发布于 2015-07-22 17:35:08
从Reactive0.12开始,大写组件是区分组件和HTML标记的反应惯例。
来自反应文件下的标记与React组件的头:
要呈现一个React组件,只需创建一个以大写字母开头的局部变量: var MyComponent =React.createClass({/*.*/});var myElement =;React.render(myElement,document.getElementById(‘document.getElementById’)); React的JSX使用大写和小写的约定来区分本地组件类和HTML标记。
https://stackoverflow.com/questions/31570025
复制相似问题