React.js集成Antd组件库

集成引用

yarn add babel-plugin-import
yarn add antd

安装完毕后,首先在index.js中引入antd的css文件

import 'antd/dist/antd.css';

之后,在需要用到antd的组件js中引入所需部件即可

import React from 'react';
import { Button } from 'antd';

class AntdTest extends React.Component {
    clickMe() {

    }

    render() {
        return (
            <div className="App">
                <Button type="primary" onClick={this.clickMe}>Primary</Button>
                <Button>Default</Button>
                <Button type="dashed">Dashed</Button>
                <Button type="danger">Danger</Button>
            </div>
        );
    }
}

export default AntdTest;
import React from 'react';
import { Button } from 'antd';

function AntdTest() {
    return (
        <div className="App">
            <Button type="primary">Primary</Button>
            <Button>Default</Button>
            <Button type="dashed">Dashed</Button>
            <Button type="danger">Danger</Button>
        </div>
    );
}

export default AntdTest;

而在IE11下,会报不支持startsWith的错
需要安装npm install --save babel-polyfill
然后在入口文件index.js中引入import 'babel-polyfill';
因为startWith是2015年语言规范里更新的,IE始终没有支持,需要用低版本的js实现高版本的js

组件操作

import React from 'react';
import { Button, notification, Icon } from 'antd';

class AntdTest extends React.Component {
    clickMe() {
        notification.open({
            message: 'Notification Title',
            description:
                'http://www.appblog.cn',
            icon: <Icon type="smile" style={{ color: '#108ee9' }} />,
        });
    };

    render() {
        return (
            <div className="App">
                <Button type="primary" onClick={this.clickMe}>Primary</Button>
                <Button>Default</Button>
                <Button type="dashed">Dashed</Button>
                <Button type="danger">Danger</Button>
            </div>
        );
    }
}

export default AntdTest;
上一篇 React+Redux基本使用流程
下一篇 React.js集成axios
目录
文章列表
1 Shopify支付网关退款接入
Shopify支付网关退款接入
2
Flutter中的剪裁
Flutter中的剪裁
3
React Native之API学习Linking跨App的通信方法(适配Android & iOS)
React Native之API学习Linking跨App的通信方法(适配Android & iOS)
4
Android 加载GIF图最佳实践方案
Android 加载GIF图最佳实践方案
5
uniCloud云函数公用模块
uniCloud云函数公用模块
最新评论
一位WordPress评论者
一位WordPress评论者
2月12日
您好,这是一条评论。若需要审核、编辑或删除评论,请访问仪表盘的评论界面。评论者头像来自 Gravatar。