我正在尝试使用webpack构建以下代码(来自material-ui网站),但我在handleClose
和handleToggle
行上获得了一个SyntaxError。我在package.json中启用了es2015
和react
个babel预设。我是否需要启用其他预设才能支持此语法?
import React from 'react';
import Drawer from 'material-ui/Drawer';
import MenuItem from 'material-ui/MenuItem';
import RaisedButton from 'material-ui/RaisedButton';
export default class DrawerUndockedExample extends React.Component {
constructor(props) {
super(props);
this.state = {open: false};
}
handleToggle = () => this.setState({open: !this.state.open});
handleClose = () => this.setState({open: false});
render() {
return (
<div>
<RaisedButton
label="Open Drawer"
onTouchTap={this.handleToggle}
/>
<Drawer
docked={false}
width={200}
open={this.state.open}
onRequestChange={(open) => this.setState({open})}
>
<MenuItem onTouchTap={this.handleClose}>Menu Item</MenuItem>
<MenuItem onTouchTap={this.handleClose}>Menu Item 2</MenuItem>
</Drawer>
</div>
);
}
}
错误:
ERROR in ./src/components/MenuBar.jsx
Module build failed: SyntaxError: /Users/simon/Desktop/rockstart
-client/src/components/MenuBar.jsx: Unexpected token (24:16)
22 | }
23 |
> 24 | _handleToggle = () => this.setState({open: !this.state.
open});
| ^
25 |
26 | _handleClose = () => this.setState({open: false});
27 |