react.js - ReactJs Cannot read property 'keys' of undefined
本文介绍了react.js - ReactJs Cannot read property 'keys' of undefined的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问 题
<!DOCTYPE html>
<html>
<head>
<title>ex 1</title>
</head>
<body>
<div id="content">
</div>
<script src="build/react.min.js"></script>
<script src="build/react-dom.min.js"></script>
<script src="https://cdn.bootcss.com/babel-core/6.1.19/browser.min.js"></script>
<script src="ex1.jsx" type="text/babel"></script>
</body>
</html>
ex1.jsx code:
var HelloWord = React.createClass({
render: function () {
return (
<div>
<p>Hello Word!</p>
</div>
);
}
});
ReactDOM.render(
<HelloWord></HelloWord>, document.getElementById('content')
);
console message after run:Uncaught TypeError: Cannot read property 'keys' of undefined
Why?
解决方案
现在的大部分项目都是用babel6去转换的,所以建议题主也换成babel6,方法如下:
新建.babelrc文件
touch .babelrc
写入依赖
{
"presets: ["es2015", "react", "stage-0"]
}
安装依赖
npm i babel-core babel-loader babel-preset-es2015 babel-preset-react babel-preset-stage-0 -D
最后配置webpack,加载babel-loader
{test: /.js/, loaders: ['babel']}
这篇关于react.js - ReactJs Cannot read property 'keys' of undefined的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文