Arrays ES6,反应错误消息我不明白
我有下一个代码:Arrays ES6,反应错误消息我不明白,arrays,reactjs,ecmascript-6,Arrays,Reactjs,Ecmascript 6,我有下一个代码: close = () => { this.setState({ open: false }); this.props.onUpdate(this.props.defaultValue); } 但我收到了下一条错误消息: ERROR in ./ui/usersModule/scripts/usersTable.jsx Module build failed: SyntaxError: Error: Unexpected token (232
close = () => {
this.setState({ open: false });
this.props.onUpdate(this.props.defaultValue);
}
但我收到了下一条错误消息:
ERROR in ./ui/usersModule/scripts/usersTable.jsx
Module build failed: SyntaxError:
Error: Unexpected token (232:8)
230 | }
231 |
> 232 | close = () => {
| ^
233 | this.setState({ open: false });
234 | this.props.onUpdate(this.props.defaultValue);
235 | }
我看到它在原始代码上编译,但由于某种原因,它没有在我的机器上编译。我需要从以下位置调用它:
onClick={ this.close }
为什么会是我的错误?还有其他方法调用关闭函数吗?如果您使用典型的webpack+babel设置来编译ES6+代码,您需要 安装模块,并将其添加到
babel
下的package.json
或您的.babelrc
中:
"plugins": [
"transform-class-properties"
]
如何在webpack.config.js上实现这一点?