官方文档: https://4x-ant-design.antgroup.com/components/button-cn
This example demonstrates how to use the Button component in Ant Design React.
import React from 'react';
import { Button } from 'antd';
function App() {
return (
<>
<Button type="primary">Primary</Button>
<Button>Default</Button>
<Button type="dashed">Dashed</Button>
<Button type="text">Text</Button>
<Button type="link">Link</Button>
</>
);
}
import React from 'react';
import { Button } from 'antd';
function App() {
return (
<>
<Button type="primary" size="large">Large</Button>
<Button type="primary" size="middle">Middle</Button>
<Button type="primary" size="small">Small</Button>
</>
);
}
import React from 'react';
import { Button } from 'antd';
import { DownloadOutlined } from '@ant-design/icons';
function App() {
return (
<>
<Button type="primary" icon={<DownloadOutlined />}>
Download
</Button>
<Button icon={<DownloadOutlined />}>Download</Button>
</>
);
}
import React, { useState } from 'react';
import { Button } from 'antd';
function App() {
const [loading, setLoading] = useState(false);
const handleClick = () => {
setLoading(true);
setTimeout(() => {
setLoading(false);
}, 2000);
};
return (
<Button type="primary" loading={loading} onClick={handleClick}>
Click Me
</Button>
);
}
import React from 'react';
import { Button } from 'antd';
const { ButtonGroup } = Button;
function App() {
return (
<ButtonGroup>
<Button>Left</Button>
<Button>Middle</Button>
<Button>Right</Button>
</ButtonGroup>
);
}
import React from 'react';
import { Button } from 'antd';
function App() {
return (
<>
<Button type="primary" disabled>Disabled Primary</Button>
<Button disabled>Disabled Default</Button>
</>
);
}
type prop for button style (primary, default, dashed, text, link)size prop for button size (large, middle, small)icon prop for icon buttonsloading prop for loading statedisabled prop to disable button