晚上好!当我在React组件中使用以下ES7代码时,我正在使用我的代码并使用Parsing error: Unexpected token =
:
static contextTypes = {
router: PropTypes.object
}
该组件是基于类的组件:
class Transactions extends Component {
我已将babel-eslint
添加到我的eslintrc.json
文件中:
{
"parser": "babel-eslint",
"plugins": [
"react",
"react-native"
],
"ecmaFeatures": {
"jsx": true
},
"extends": ["standard", "standard-react"]
}
依赖项的版本在我的package.json
中设置如下:
"babel-eslint": "^6.0.4",
"eslint-plugin-babel": "^3.2.0",
"eslint-plugin-react": "^5.0.1",
"eslint": "^2.2.0",
"eslint-config-standard": "^5.1.0",
"eslint-config-standard-jsx": "^1.1.1",
"eslint-config-standard-react": "^2.3.0",
"eslint-loader": "^1.3.0",
"eslint-plugin-promise": "^1.0.8",
"eslint-plugin-react": "^4.1.0",
"eslint-plugin-standard": "^1.3.2"
任何想法都会很好,除了使用babel-eslint
作为解析器之外,还在努力寻找在线解决方案。
谢谢: - )
答案 0 :(得分:1)
您应该将您的contextTypes放在班级之外。
示例:
class Transactions extends Component {
....
....
}
Transactions.contextTypes = {
router: PropTypes.object
}