一、安装AntD

  1. yarn add antd

二、引入AntD的CSS样式

  1. import "antd/dist/antd.css"

三、在官方文档寻找自己需要的组件并使用

例如:Button

  1. 先import组件到页面
  1. import { Button } from "antd"
  1. 直接使用
  1. function Demo(){
  2. return (
  3. <>
  4. <Button type="primary">主按钮</Button>
  5. <Button>次按钮</Button>
  6. </>
  7. )
  8. }

例如:Form

  1. 先import组件到页面
  1. import { Form, Input, Button, checkbox } from "antd"
  1. 直接使用
  1. const layout = {
  2. labelCol: { span: 8 },
  3. wrapperCol: { span: 16 }
  4. }
  5. const tailLayout = {
  6. wrapperCol: { offset: 8, span: 16 }
  7. }
  8. const Demo = () => {
  9. const onFinish = values => {
  10. console.log("Success:", values)
  11. }
  12. const onFinishFailed = errorInfo => {
  13. console.log("Failed:", errorInfo)
  14. }
  15. return (
  16. <Form
  17. {...layout}
  18. name="basic"
  19. initialValues={{
  20. remember: true,
  21. }}
  22. onFinish={onFinish}
  23. onFinishFailed={onFinishFailed}
  24. >
  25. <Form.Item
  26. label="Username"
  27. name="username"
  28. rules={[
  29. {
  30. required: true,
  31. message: "Please input your username!",
  32. },
  33. ]}
  34. >
  35. <Input/>
  36. </Form.Item>
  37. <Form.Item
  38. label="Password"
  39. name="password"
  40. rules={[
  41. {
  42. required: true,
  43. message: "Please input your password!",
  44. },
  45. ]}
  46. >
  47. <Input.Password/>
  48. </Form.Item>
  49. <Form.Item {...tailLayout} name="remember" valuePropName="checked">
  50. <Checkbox>Remember me</Checkbox>
  51. </Form.Item>
  52. <Form.Item {...tailLayout}>
  53. <Button type="primary" htmlType="submit">
  54. Submit
  55. </Button>
  56. </Form.Item>
  57. </Form>
  58. )
  59. }
  1. 修改里面的参数达到自己的效果