Antd組件庫使用方法


零、介紹:

Ant design,是阿里巴巴的螞蟻金服公司設計的一套適應用於web端和移動端網頁的Ui組件庫,組件好看,非常適合React框架使用。

官網:https://ant.design/index-cn

 

一、第一步:安裝包

引包:cnpm i -S antd

 

二、全局引用、其實都不這么用,因為需要引用的文件太大,影響性能、所以這里忽略。

 

三、按需加載、想用什么組件就引入什么組件

1.安裝依賴:兩個包

cnpm i -D react-app-rewired customize-cra

 

2.把pakage.json文件的scripts的react-scripts替換成react-app-rewired

1 /* package.json */
2 "scripts": {
3 -   "start": "react-scripts start",//原來
4 +   "start": "react-app-rewired start",//修改
5 -   "build": "react-scripts build",
6 +   "build": "react-app-rewired build",
7 -   "test": "react-scripts test",
8 +   "test": "react-app-rewired test",
9 }

 

3.安裝插件  cnpm i -S babel-plugin-import

 

4.在項目根目錄創建一個 config-overrides.js 用於修改默認配置。

1 const { override, fixBabelImports } = require('customize-cra');
2 
3 module.exports = override(
4   fixBabelImports('import', {
5     libraryName: 'antd',
6     libraryDirectory: 'es',
7     style: 'css',
8   }),
9 );

 

四、使用

 1 import React, { Component } from 'react'
 2 import { Button } from 'antd'; //單獨引用
 3 
 4 export default class About extends Component {
 5   render() {
 6     return (
 7       <div>
 8         關於
 9         {/* 使用按鈕組件 */}
10         <Button type="primary">Primary</Button>
11       </div>
12     )
13   }
14 }

 

五、頁面效果


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM