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>
    );
  }
}
相关推荐
kerli4 分钟前
基于 kmp/cmp 的跨平台图片加载方案 - 适配 Android View/Compose/ios
android·前端·ios
RONIN19 分钟前
vue组件、组件生命周期、组件分离模块化
前端·vue.js
小强198820 分钟前
HTML5语义化标签:从`div`到`article`与`section`的进化之路
前端
RONIN20 分钟前
vue开发环境与基础语法、计算属性、侦听属性
前端·vue.js
WayneYang27 分钟前
JavaScript ES6+ (ES2015~ES2024) 全特性整理
前端·javascript
逆光如雪28 分钟前
移动端border-left 和 width:1px,同样写1px为什么粗细不同?
前端·css
千寻girling29 分钟前
被内推的面试 , 第一次
java·前端·python·面试·职场和发展·typescript·node.js
JustNow_Man40 分钟前
Bun 常用命令速查清单(TypeScript 编译篇)
前端·javascript·typescript
anyup1 小时前
uni-app 全能日历组件,支持农历、酒店预订、打卡签到、价格日历多种场景
前端·前端框架·uni-app
|晴 天|1 小时前
从零打造现代化个人博客:Vue 3 + TypeScript + Element Plus 完整实战
javascript·css·chrome·typescript·html5·webstorm