网上常见方法全是安装 babel-plugin-transform-decorators-legacy 然后添加babel配置的,

实际情况是最新版本的create-react-app 生成的项目已经是基于babel7了,

所以我们需要安装 @babel/plugin-proposal-decorators 替换 旧版的babel-plugin-transform-decorators-legacy  ,

然后添加babel配置 

{
  "plugins": [
    ["@babel/plugin-proposal-decorators", { "legacy": true }],
  ]
}

 

这一点 通过看 babel-plugin-transform-decorators-legacy库的npm的readme可以获得信息

截图如下

create-react-app 支持 装饰器 decorator

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-14
  • 2022-01-13
  • 2021-06-19
  • 2021-12-14
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-12-09
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案