reactjs无法读取未定义的属性“键” [英] reactjs Cannot read property 'keys' of undefined
问题描述
我正在通过教程学习reactjs并遇到了这个错误。这说无法读取未定义的属性'键'我的代码非常小,所以我认为它与语言的结构有关。有谁知道这个问题和可能的解决方案?
I am learning reactjs through a tutorial and ran into this error. That says "Cannot read property 'keys' of undefined" My code is very minimal so I assume that it has to do with the structure of the language. Does anyone know the problem and a possible solution?
<!DOCTYPE html>
<html>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.0.1/react.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.0.1/react-dom.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-core/6.1.19/browser.min.js"></script>
<title>ReactJs</title>
</head>
<body>
<div id="app"></div>
<script type="text/babel">
var HelloWorld = ReactDOM.createClass({
render: function() {
return
<div>
<h1>Hello World</h1>
<p>This is some text></p>
</div>
}
});
ReactDOM.render(
<HelloWorld />, document.getElementById('app'));
</script>
</body>
</html>
推荐答案
编辑:奇怪的是,在我们上面的评论之后,我查了一下看看它是不是真正的babel核心版本,我在我的小提琴中使用这个:
oddly, after our comments above, I checked to see if it was indeed the babel core version, I am using this one in my fiddle:
https://cdnjs.cloudflare.com /ajax/libs/babel-core/5.8.24/browser.js
第二个我切换到你上面的版本我得到了这个:
The second I switch to your version above I get this:
Uncaught TypeError: Cannot read property 'keys' of undefined
使用 React.createClass
不是 ReactDOM.createClass
并换行括号中的多行html如下:
Use React.createClass
not ReactDOM.createClass
and wrap multiple lines of html in parenthesis like so:
工作示例: https:// jsfiddle.net/69z2wepo/38998/
var Hello = React.createClass({
render: function() {
return (
<div>
<h1>Hello World</h1>
<p>This is some text</p>
</div>
)
}
});
ReactDOM.render(
<Hello name="World" />,
document.getElementById('container')
);
这篇关于reactjs无法读取未定义的属性“键”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!