網站首頁 編程語言 正文
0.前言
我們在后臺管理系統React項目開發中會有Table表格、Form表單、List列表、Button按鈕等組件,這個時候我們可以使用AntDesign來減少開發中不必要的樣式問題。
1.AntDesign是什么?
Ant Design 是一個 UI 設計語言,是一套提煉和應用于企業級后臺產品的交互語言和視覺體系
2.AntDesign如何使用?
首先你要安裝 yarn
或npm
或cnpm
$ yarn create react-app antd-demo # or $ npx create-react-app antd-demo # or $ npm create react-app antd-demo // 若網絡緩慢可使用cnpm淘寶鏡像 $ cnpm create react-app antd-demo
工具會自動初始化一個腳手架并安裝 React 項目的各種必要依賴
然后我們進入項目并啟動。
$ cd antd-demo $ yarn/npm/cnpm start
此時瀏覽器會訪問?http://localhost:3000/?,看到?Welcome to React
?的界面就算成功了。
而后需要引入AntD
現在從 yarn 或 npm 安裝并引入 antd。
$ yarn add antd
3.如何具體使用AntDdesign的組件
通用步驟是,先用import引入antd的具體某一個組件,然后根據規則及API使用
例:
3-1.如何使用 antd 的Table組件
import React from 'react'; import { Table } from 'antd'; import './App.css'; const columns = [ { title: 'Name', dataIndex: 'name', key: 'name', render: text => <a>{text}</a>, }, { title: 'Age', dataIndex: 'age', key: 'age', }, ]; const data = [ { key: 1, name: 'one', age: '10', }, { key: 2, name: 'two', age: '20', }, ]; const App = () => ( <div className="App"> <Table columns={columns} dataSource={data} /> </div> ); export default App;
樣式如圖:
3-2.如何使用 antd 的Button組件
import React from 'react'; import { Button } from 'antd'; const App = () => ( <div className="App"> <Button type="primary">Primary Button</Button><br/> <Button>Default Button</Button><br/> <Button type="dashed">Dashed Button</Button><br/> <Button type="text">Text Button</Button><br/> <Button type="link">Link Button</Button><br/> </div> ); export default App;
4.后續
總結:總體來說要使用ant具體的某一個組件,就要仔細觀看組件的API,以API為基準來進行開發。
好處:用Ant開發,省去了寫css樣式的問題,同時,組件里也有相應的JS方法,便于開發
原文鏈接:https://juejin.cn/post/7085170302170202142
相關推薦
- 2022-04-04 react報錯‘react-scripts‘ 不是內部或外部命令,也不是可運行的程序
- 2022-03-07 golan參數校驗Validator_Golang
- 2022-10-27 計算機系統匯編語言和機器語言深入理解_匯編語言
- 2022-09-22 vrrp協議與keepalived淺析
- 2022-09-07 詳解C語言結構體,枚舉,聯合體的使用_C 語言
- 2022-07-03 YOLOv5中SPP/SPPF結構源碼詳析(內含注釋分析)_python
- 2022-07-25 C/C++實現線性順序表的示例代碼_C 語言
- 2022-07-27 C++詳細講解圖的拓撲排序_C 語言
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支