「Ant Design」Antd 中卡片如何完全不展示内容区域、按需展示内容区域、不展示标题

前言

下面是默认的 Antd 卡片,由以下区域组成

处理 Antd 的 Card 展示形式大致有下面三种

卡片完全不展示内容区域

复制代码
const App = () => (
    <Card title="Default size card" extra={<a href="#">More</a>} 
    style={{ width: 300 }}
    bodyStyle={{display:'none'}}>
      <p>Card content</p>
    </Card>
);

按需展示内容区域

引入一个状态

复制代码
import React, { useState } from 'react';
import { Card, Button } from 'antd';
import 'antd/dist/reset.css';

const App = () => {
  const [showContent, setShowContent] = useState(false);

  return (
    <Card
      title="这是标题"
      extra={<a href="#">更多</a>}
      style={{ width: 300 }}
    >
      {showContent && (
        <div>这是内容区域</div>
      )}
      <Button onClick={() => setShowContent(!showContent)}>
        切换内容显示
      </Button>
    </Card>
  );
};

export default App;

不展示标题区域

复制代码
import { Card } from 'antd';
import React from 'react';
const App = () => (
    <Card  
    style={{ width: 300 }}
>
      <p>Card content</p>
    </Card>
);
相关推荐
jjw_zyfx1 小时前
css vue vite实现闪烁的呼吸效果
javascript·css·vue.js
sunly_2 小时前
React useActionState 的用法详解
前端·javascript·react.js
cyadyx2 小时前
【Three.js】Three.js 中加载 3D 模型
前端·javascript·3d
汉堡大王95272 小时前
前端工程师 TypeScript 上手指南:一条清晰的从入门到精通路线
前端·javascript·react.js
wear工程师2 小时前
防抖为什么会失效?React 面试里的闭包和定时器
javascript·react.js
浅水壁虎2 小时前
vue基础(第四章 Pinia)
前端·javascript·vue.js
张元清3 小时前
React useEventSource Hook:自带断线重连的 Server-Sent Events (2026)
javascript·react.js
光影少年3 小时前
RN 网络请求:Fetch / Axios 封装、超时、拦截器
前端·react native·react.js
铁皮饭盒4 小时前
网页端, 6.5MB人脸识别模型, 谷歌框架, 又快又准
前端·javascript·后端
自进化Agent智能体4 小时前
Hermes 工具与工具集——Hermes 的内置能力
javascript