Using the export keyword between a decorator and a class is not allowed(脚手架修饰器的问题)

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

@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
        }
      ]
    ]
  },

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

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容