【发布时间】:2017-10-01 13:32:24
【问题描述】:
当创建一个计算点击次数的简单按钮时,我在按钮标签上得到了意外的令牌错误(我可以说)没有原因
import React from 'react';
/**
* A counter button: tap the button to increase the count.
*/
class Counter extends React.Component {
constructor() {
super();
this.state = {
count: 0,
};
}
render() {
return (
<button onClick={() => {this.setState({ count: this.state.count + 1 });}}>
Count: {this.state.count}
</button>
);
}
}
export default Counter;
【问题讨论】:
-
您的代码在我的系统上运行良好。你能发布你得到的确切错误吗?
-
@LuiGiovanni 你在编译吗?不,我正在编译你需要使用像 babel 这样的 ES6 to ES5 transpiler 将你用 ES6 编写的 React 代码转译成 ES5,这样浏览器才能理解 JS 代码。