【发布时间】:2015-05-07 18:03:33
【问题描述】:
我不明白为什么会出现这个错误以及出现什么错误 - 你知道为什么吗?
更新:我在 nginx docker 容器中运行它。
错误信息:
Uncaught Error: Parse Error: Line 10: Unexpected token ILLEGAL
at http://x.x.x.x/scripts/example.js:10:undefined
enter code here... R OTHER DEALINGS IN THE SOFTW
index.html
<!DOCTYPE html>
<html>
<head>
<title>Hello React</title>
<!-- Not present in the tutorial. Just for basic styling. -->
<link rel="stylesheet" href="css/base.css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.13.0/react.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.13.0/JSXTransformer.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/marked/0.3.2/marked.min.js"></script>
</head>
<body>
<div id="content"></div>
<script type="text/jsx;harmony=true" src="scripts/example.js"></script>
</body>
</html>
脚本/example.js
var Simple = React.createClass({
getInitialState: function(){
return { count: 0 };
},
handleMouseDown: function(){
alert('I was told: ' + this.props.message);
this.setState({ count: this.state.count + 1});
},
render: function(){
return <div>
<div className="clicker" onMouseDown={this.handleMouseDown}>
Give me the message!
</div>
<div className="message">Message conveyed
<span className="count">{this.state.count}</span> time(s)</div>
</div>
;
}
});
React.render(<Simple message="Keep it Simple"/>,
document.body);
【问题讨论】:
-
我将您的代码放入 jsfiddle 中(只需更改
renderComponent=>render即可更新到最新的 ReactJS 表单),它似乎可以工作:jsfiddle.net/smmccrohan/vmthzsj5 -
好的,谢谢。我在带有 nginx 的 docker 容器中运行它,然后我收到错误 - 嗯?
-
有趣。我认为您的问题出在执行环境中。您的代码本身看起来还不错。
-
好的,感谢收看。