Ant Design使用方法
生活随笔
收集整理的這篇文章主要介紹了
Ant Design使用方法
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1.antd官網:
https://ant.design/docs/react/introduce-cn2、React中使用Antd
1、安裝antd npm install antd --save / yarn add antd / cnpm install antd --save2、在您的react項目的css文件中引入 Antd的css@import '~antd/dist/antd.css';3、看文檔使用:
如使用Button:1、在對應的組件中引入Antd import { Button } from 'antd';2、<Button type="primary">Primary</Button>4、React中使用Antd高級配置,按需引入css樣式(該步驟在一定程度上提高用戶體驗,但也可以不配置)
我們現在已經把組件成功運行起來了,但是在實際開發過程中還有很多問題,例如上面的例子實際上加載了全部的 antd 組件的樣式(對前端性能是個隱患)。 1、安裝antd npm install antd --save2、安裝(react-app-rewired)一個對 create-react-app 進行自定義配置的社區解決方案yarn add react-app-rewired / cnpm install react-app-rewired --save3、修改 package.jsonreact-scripts 需改為react-app-rewired"scripts": {"start": "react-app-rewired start","build": "react-app-rewired build","test": "react-app-rewired test --env=jsdom","eject": "react-app-rewired eject"}4、安裝babel-plugin-import babel-plugin-import是一個用于按需加載組件代碼和樣式的 babel 插件yarn add babel-plugin-import / cnpm install babel-plugin-import --save5、在項目根目錄創建一個 config-overrides.js 配置文件const { injectBabelPlugin } = require('react-app-rewired');module.exports = function override(config, env) {config = injectBabelPlugin(['import', { libraryName: 'antd', libraryDirectory: 'es', style: 'css' }],config,);return config;};6、然后移除前面在 src/App.css 里全量添加的 @import '~antd/dist/antd.css'; 直接引入組件使用就會有對應的cssimport { Button } from 'antd';<Button type="primary">Primary</Button>?
轉載于:https://www.cnblogs.com/ywjfx/p/10435404.html
總結
以上是生活随笔為你收集整理的Ant Design使用方法的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 从源码来理解slf4j的绑定,以及log
- 下一篇: 校内oj??!