JavaScriptJavaScript

Using the export keyword between

2019-01-17  本文已影响387人  一支桨

当你修饰器函数这样写的时候

@connect('aaa')
export default class AppView extends React.Component{
    render(){
       //....
    }
  }

出现的问题为:

Parsing error: Using the export keyword between a decorator and a class is not allowed. Please use `export @dec class` instead.

解决方案:
安装依赖:

npm install --save-dev @babel/plugin-proposal-decorators
npm install --save-dev babel-plugin-transform-decorators-legacy

修改jsx文件

@connect('aaa')
 class AppView extends React.Component{
    render(){
       //....
    }
  }
export default AppView 

更改package.json文件中的babel配置

"babel": {
    "presets": [
      "react-app"
    ],
    "plugins": [
      [
        "@babel/plugin-proposal-decorators",
        {
          "legacy": true
        }
      ],
      [
        "@babel/plugin-proposal-class-properties",
        {
          "loose": true
        }
      ]
    ]
  },

再次运行你的项目,就发现解决了刚才的问题

上一篇下一篇

猜你喜欢

热点阅读