我正在尝试开始在ReactJS中构建网站。但是,当我尝试将JS放在单独的文件中时,我开始收到此错误:“ Uncaught SyntaxError:Unexpected token <”。
我尝试添加/** @jsx React.DOM */
到JS文件的顶部,但没有解决任何问题。以下是HTML和JS文件。关于出什么问题有什么想法吗?
的HTML
<html>
<head>
<title>Page</title>
<script src="http://fb.me/react-0.12.2.js"></script>
<script src="http://fb.me/JSXTransformer-0.12.2.js"></script>
<script src="http://code.jquery.com/jquery-1.10.0.min.js"> </script>
<script src="./lander.js"> </script>
</head>
<body>
<div id="content"></div>
<script type="text/jsx">
React.render(
<Lander />,
document.getElementById('content')
);
</script>
</body>
</html>
JS
/**
* @jsx React.DOM
*/
var Lander = React.createClass({
render: function () {
var info = "Lorem ipsum dolor sit amet... ";
return(
<div>
<div className="info">{info}</div>
</div>
);
}
});
编辑:我意识到我需要添加type="text/jsx"
到包括我的着陆器代码的脚本标签。但是,添加并重新加载后,我得到此警告
“您正在使用的浏览器JSX变压器一定要预编译JSX生产- http://facebook.github.io/react/docs/tooling-integration.html#jsx ”
随后出现此错误:
"XMLHttpRequest cannot load file:///Users/.../lander.js. Cross origin requests are only supported for protocol schemes: http, data, chrome-extension, https, chrome-extension-resource."
it seems like there is something else that I need to do in order to get in browser jsx transform working, but I'm not sure what it is.
EDIT: OOOOH do I need to host it using MAMP or something?
如果遇到这样的错误:
可能是您缺少大括号