Ant Design使用方法
生活随笔
收集整理的這篇文章主要介紹了
Ant Design使用方法
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
1.antd官網(wǎng):
https://ant.design/docs/react/introduce-cn2、React中使用Antd
1、安裝antd npm install antd --save / yarn add antd / cnpm install antd --save2、在您的react項(xiàng)目的css文件中引入 Antd的css@import '~antd/dist/antd.css';3、看文檔使用:
如使用Button:1、在對(duì)應(yīng)的組件中引入Antd import { Button } from 'antd';2、<Button type="primary">Primary</Button>4、React中使用Antd高級(jí)配置,按需引入css樣式(該步驟在一定程度上提高用戶體驗(yàn),但也可以不配置)
我們現(xiàn)在已經(jīng)把組件成功運(yùn)行起來了,但是在實(shí)際開發(fā)過程中還有很多問題,例如上面的例子實(shí)際上加載了全部的 antd 組件的樣式(對(duì)前端性能是個(gè)隱患)。 1、安裝antd npm install antd --save2、安裝(react-app-rewired)一個(gè)對(duì) create-react-app 進(jìn)行自定義配置的社區(qū)解決方案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是一個(gè)用于按需加載組件代碼和樣式的 babel 插件yarn add babel-plugin-import / cnpm install babel-plugin-import --save5、在項(xiàng)目根目錄創(chuàng)建一個(gè) 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'; 直接引入組件使用就會(huì)有對(duì)應(yīng)的cssimport { Button } from 'antd';<Button type="primary">Primary</Button>?
轉(zhuǎn)載于:https://www.cnblogs.com/ywjfx/p/10435404.html
總結(jié)
以上是生活随笔為你收集整理的Ant Design使用方法的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 从源码来理解slf4j的绑定,以及log
- 下一篇: 校内oj??!