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>
    );
  }
}
相关推荐
Momo__1 小时前
VueUse createReusableTemplate —— 单文件组件内的模板复用神器
前端·vue.js
无名氏同学1 小时前
React 16-19 新特性
react.js
程序员小富1 小时前
我开源了一个开发者专属的智能 JSON 工具,得到了媳妇高度认可
前端·vue.js·后端
小小小小宇1 小时前
程序员如何给 LLM 装工具以及看懂推理过程
前端
写代码的皮筏艇1 小时前
React中的forwardRef
前端·react.js·面试
Flynt1 小时前
装上TypeScript 7.0 RC之后,最让我意外不是10倍提速
typescript·visual studio code
疯狂SQL1 小时前
手写高性能在线 JSON 工具|Web Worker 工程化打包 + 语法自动修复 + 多语言代码生成实战
typescript·json·next.js·web worker·前端性能优化·esbuild·源码实战
槑有老呆1 小时前
花三个月工资请了个 AI 程序员,结果它连青岛啤酒股价都查不了
前端
风骏时光牛马1 小时前
Verilog开发常见问题汇总解析
前端
子兮曰1 小时前
AI Coding Method Map:一张图看懂 AI 编程的完整链路
前端·人工智能·后端