Webpack掉坑之路(2)——Antd組件引用

注:本文部分內(nèi)容來自官網(wǎng),如有問題請參考如下網(wǎng)站

https://ant.design/docs/react/introduce-cn

1. 請先完成掉坑之路(1)的內(nèi)容再進(jìn)行本文內(nèi)容。

2. 安裝antd依賴:

> npm install --save-dev antd

3. 安裝babel-plugin-import:

> npm install --save-dev babel-plugin-import

4. 在根目錄下創(chuàng)建一個.babelrc文件:

//.babelrc
{
  "plugins": [
    ["import", {
      "libraryName": "antd",
      "libraryDirectory": "es",
      "style": "css" // `style: true` 會加載 less 文件
    }]
  ]
}

5. 測試:

首先引入antd包

import {Button, Layout} from 'antd';
const {Header, Content, Footer} = Layout;

然后調(diào)用Button組件以及布局組件,下面只展示Button使用示例

<Button htmlType={'submit'}>Button</Button>

附錄

//app/main.js
import React,{Component} from 'react';
import ReactDOM from 'react-dom';
import {Button, Layout} from 'antd';
const {Header, Content, Footer} = Layout;

class App extends Component{
    render(){
        return (
        <div>
            <Header>
                Hello, world!
            </Header>

            <Content style={{width:'1200px', height: '500px', textAlign:"center"}}>
                <Button htmlType={'submit'}>
                    Button
                </Button>
            </Content>

            <Footer style={{textAlign: 'center'}}>
                This is Footer<br/>
                By Victor Lin
            </Footer>
        </div>
    );
    }
}

ReactDOM.render(
<App/>,
    document.getElementById('root')
)

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 學(xué)習(xí)筆記 原文地址:antDesignPro使用心得,快速開發(fā)必備。https://www.52pojie.cn/...
    kalshen閱讀 44,937評論 8 85
  • 相關(guān)文章和閱讀順序 搭建Typescript+React項目模板(1) --- 項目初始化搭建 Typescrip...
    大春春閱讀 6,034評論 2 9
  • 寫在前面的話 閱讀本文之前,先看下面這個webpack的配置文件,如果每一項你都懂,那本文能帶給你的收獲也許就比較...
    不忘初心_9a16閱讀 3,338評論 0 16
  • 名詞解釋 通常我們在conatiner中引入一個ant-design的component都會使用import將組件...
    張培_閱讀 2,174評論 0 1
  • 黃紗帳,長又長 一縷青煙火正著,絲成繞,構(gòu)出遠(yuǎn)邊疆。 破布窗,涼又涼 一輪幽月淡如霜,淚成殤,扯斷粗家紡。
    顧粵閱讀 279評論 0 1

友情鏈接更多精彩內(nèi)容