构建此代码需要加载程序吗?

时间:2016-07-06 18:34:23

标签: reactjs ecmascript-6 babel

我正在尝试使用webpack构建以下代码(来自material-ui网站),但我在handleClosehandleToggle行上获得了一个SyntaxError。我在package.json中启用了es2015react个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 |

0 个答案:

没有答案