美文网首页JavaScriptJavaScript
Using the export keyword between

Using the export keyword between

作者: 一支桨 | 来源:发表于2019-01-17 13:54 被阅读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
        }
      ]
    ]
  },

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

相关文章

网友评论

    本文标题:Using the export keyword between

    本文链接:https://www.haomeiwen.com/subject/oshidqtx.html