Form.create
方法是一個典型的裝飾器,因而就改爲裝飾器的寫法
yarn add @babel/plugin-proposal-decorators --save
二、將.webpackrc 改爲.webpackrc.js而後具體配置css
const config = {}; //用於跨域 config.proxy = { "/api": { "target": "http://localhost:7001", "changeOrigin": true, "pathRewrite": { "^/api": "" } } } //antd按需加載引入 config.extraBabelPlugins = [ ["import", { "libraryName": "antd", "libraryDirectory": "es", "style": "css" }], //裝飾器語法配置 [ "@babel/plugin-proposal-decorators", { "legacy": true } ] ] export default config;
一、先安裝包 react
yarn add @babel/plugin-proposal-decorators --save
二、在項目根目錄下建立.babelrc, config-overrides.js文件webpack
{ "presets": [ "react-app" ], "plugins": [ [ "import", { "libraryName": "antd", "libraryDirectory": "es", "style": "css" // `style: true` 會加載 less 文件 } ], [ "@babel/plugin-proposal-decorators", { "legacy": true } ] ] }
三、刪除package.json的babel配置web
// 刪除下面幾行 "babel": { "presets": [ "react-app" ] },
這樣咱們就能夠使用裝飾器語法了json
裝飾器 語法使用以前 拿antd的包爲例子api