【发布时间】:2018-06-19 19:33:21
【问题描述】:
我想这样使用状态:
class Checkout extends Component {
state = {
ingredients: null,
totalPrice: 0
};
但是我收到了错误提示 Unexpected token =,我知道这可以通过 babel-plugin-transform-class-properties 解决,不幸的是它不适用于我的情况。
这是我的 package.json
"babel": {
"presets": [
"env",
"react-app"
],
"plugins": ["transform-class-properties"]
},
"eslintConfig": {
"extends": "react-app"
},
"devDependencies": {
"babel-plugin-transform-class-properties": "^6.24.1",
"babel-preset-env": "^1.7.0",
"eslint": "^4.19.1",
"eslint-plugin-react": "^7.1.0"
}
知道这里还有什么问题吗?
【问题讨论】:
-
是 babel 抛出错误,还是你的浏览器。只要它被转译,它看起来应该可以工作。
-
@samanime AFAIK 那是 Babel 在扔这个。
-
您能否将 Babel 的完整输出添加到针对一个小示例(如您共享的示例)运行时出现的错误?
标签: javascript reactjs ecmascript-6 babeljs