【问题标题】:material-ui Component Demos can't workmaterial-ui Component Demos 不能工作
【发布时间】:2018-07-01 06:48:49
【问题描述】:

我尝试运行App Bar 演示中的最后一个示例,但出现错误:

ERROR in ./src/Root.js
Module build failed: SyntaxError: Unexpected token (28:8)
  26 | 
  27 | class MenuAppBar extends React.Component {
> 28 |   state = {
     |         ^
  29 |     auth: true,
  30 |     anchorEl: null,
  31 |   };

部分代码

class MenuAppBar extends React.Component {
  state = {
    auth: true,
    anchorEl: null,
  };

  handleChange = (event, checked) => {
    this.setState({ auth: checked });
  };

  handleMenu = event => {
    this.setState({ anchorEl: event.currentTarget });
  };

  handleClose = () => {
    this.setState({ anchorEl: null });
  };

依赖

  • “material-ui”:“^1.0.0-beta.30”
  • “反应”:“^16.2.0”
  • “react-dom”:“^16.2.0”
  • “babel-cli”:“^6.26.0”
  • “babel-core”:“^6.26.0”
  • “babel-loader”:“^7.1.2”
  • “babel-preset-env”:“^1.6.1”
  • "babel-preset-es2017": "^6.24.1"
  • “babel-preset-react”:“^6.24.1”
  • “webpack”:“^3.10.0”

.babelrc

{
    "presets": ["env","react"]
}

如何运行它?

【问题讨论】:

标签: material-ui


【解决方案1】:

我会稍微检查一下 MUI 的 GitHub 存储库中列出的预设 在这里:

https://github.com/mui-org/material-ui/blob/v1-beta/.babelrc

您可能需要其他一些预设才能像这样运行它。 还要检查您是否正在运行他们正在使用的对象分配所需的插件

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-04-10
    • 1970-01-01
    • 1970-01-01
    • 2020-07-18
    • 2021-08-09
    • 2020-05-04
    • 2016-08-21
    相关资源
    最近更新 更多