react-redux中connect使用装饰器的方式写

1.安装插件babel-plugin-transform-decorators-legacy

2.npm run eject 弹出react插件

3.package.json中babel上加入"plugins": ["transform-decorators-legacy"]

"babel": {
    "presets": [
      "react-app"
    ],
    "plugins": [
      "transform-decorators-legacy"
    ]
  },

4.

@connect(
  state=>({num : state}),
  {add , remove , addAsync}
)

后续报错 The 'decorators' plugin requires a 'decoratorsBeforeExport' option, whose value must be a boolean

The 'decorators' plugin requires a 'decoratorsBeforeExport' option, whose value must be a boolean. If you are migrating from Babylon/Babel 6 or want to use the old decorators proposal, you should use the 'decorators-legacy' plugin instead of 'decorators'.

解决方案

猜你喜欢

转载自blog.csdn.net/qq_41834059/article/details/81262030