React TypeScript | 快速了解 antd 的使用

1. 安装:

就像安装其他插件库一样,在项目文件夹下执行:

shell 复制代码
npm install antd --save

如果你安装了 yarn,也可以执行:

shell 复制代码
yarn add antd

2. 引用

typescript 复制代码
import { Button, Tooltip } from "antd";
import "antd/dist/antd.css";

注意不要忘了引用样式,否则代码没问题显示会出问题。

3. 使用

如下,一个简单 demo:

完整代码:

typescript 复制代码
import { Component } from "react";
import { Button, Tooltip } from "antd";
import "antd/dist/antd.css";

export default class AntdPage extends Component {
  render() {
    return (
      <div style={{ margin: "50px" }}>
        <p>在 Ant Design 中我们提供了五种按钮。</p>
        <Button type="primary">Primary Button</Button>
        <Button>Default Button</Button>
        <Button type="dashed">Dashed Button</Button>
        <br />
        <Button type="text">Text Button</Button>
        <Button type="link">Link Button</Button>
        <br />
        {/* 文字提示 */}
        <Tooltip title="prompt text">
          <span>Tooltip will show on mouse enter.</span>
        </Tooltip>
        <Tooltip placement="topLeft" title="Prompt Text">
          <Button>Align edge / 边缘对齐</Button>
        </Tooltip>
        {/* 等价于 */}
        <Tooltip
          placement="topLeft"
          title="Prompt Text"
          arrowPointAtCenter={false}
        >
          <Button>Align edge / 边缘对齐</Button>
        </Tooltip>
        <Tooltip placement="topLeft" title="Prompt Text" arrowPointAtCenter>
          <Button>Arrow points to center / 箭头指向中心</Button>
        </Tooltip>
        {/* 自定义children */}
        <Tooltip placement="bottom" title="提示文本" arrowPointAtCenter>
          <div
            style={{
              width: "50px",
              height: "50px",
              backgroundColor: "red",
              margin: "30px",
            }}
          >
            <p>自定义child</p>
          </div>
        </Tooltip>
      </div>
    );
  }
}
相关推荐
一斤代码2 小时前
vue3 下载图片(标签内容可转图)
前端·javascript·vue
中微子2 小时前
React Router 源码深度剖析解决面试中的深层次问题
前端·react.js
光影少年2 小时前
从前端转go开发的学习路线
前端·学习·golang
中微子2 小时前
React Router 面试指南:从基础到实战
前端·react.js·前端框架
3Katrina2 小时前
深入理解 useLayoutEffect:解决 UI "闪烁"问题的利器
前端·javascript·面试
前端_学习之路3 小时前
React--Fiber 架构
前端·react.js·架构
coderlin_3 小时前
BI布局拖拽 (1) 深入react-gird-layout源码
android·javascript·react.js
甜瓜看代码4 小时前
1.
react.js·node.js·angular.js
伍哥的传说4 小时前
React 实现五子棋人机对战小游戏
前端·javascript·react.js·前端框架·node.js·ecmascript·js
qq_424409194 小时前
uniapp的app项目,某个页面长时间无操作,返回首页
前端·vue.js·uni-app