Skip to content
TheChatArchiveThe Chat Archive
gpt-4-0314· OpenAIAi2 WildChat-4.8M (AI2)

用react+antd+ts 设计一个首页样式包含搜索框、我的待办、我的历史、我的关注、我的浏览历史,和三个带阴影的卡片分别是新闻 、动态追踪、交易日历

  1. User

    用react+antd+ts 设计一个首页样式包含搜索框、我的待办、我的历史、我的关注、我的浏览历史,和三个带阴影的卡片分别是新闻 、动态追踪、交易日历

  2. Assistant

    首先,确保你已安装了必要的依赖项:

    npm install --save react react-dom antd
    npm install --save-dev typescript @types/react @types/react-dom
    

    新建一个App.tsx文件,并编写以下代码:

    import React from 'react';
    import { Input, Row, Col, Card, Avatar, List, Typography } from 'antd';
    import { UserOutlined } from '@ant-design/icons';
    import 'antd/dist/antd.css';
    
    const { Search } = Input;
    const { Meta } = Card;
    const { Title } = Typography;
    
    const App: React.FC = () => {
      const data = [
        '我的待办',
        '我的历史',
        '我的关注',
        '我的浏览历史',
      ];
    
      return (
        <div>
          <Row>
            <Col span={12} offset={6}>
              <Search
                placeholder="搜索"
                onSearch={(value) => console.log(value)}
                style={{ marginBottom: 20 }}
              />
            </Col>
          </Row>
          <Row gutter={[24, 24]} justify="center">
            <Col xs={24} sm={12} lg={6}>
              <List
                bordered
                header={<Title level={4}>我的内容</Title>}
                dataSource={data}
                renderItem={(item) => (
                  <List.Item>
                    <Typography.Text mark>[ITEM]</Typography.Text> {item}
                  </List.Item>
                )}
              />
            </Col>
            <Col xs={24} sm={12} lg={6}>
              <Card
                hoverable
                cover={
                  <img
                    alt="news"
                    src="https://gw.alipayobjects.com/zos/rmsportal/JiqGstEfoWAOHiTxclqi.png"
                  />
                }
              >
                <Meta title="新闻" description="及时了解最新资讯" />
              </Card>
            </Col>
            <Col xs={24} sm={12} lg={6}>
              <Card
                hoverable
                cover={
                  <img
                    alt="dynamic"
                    src="https://gw.alipayobjects.com/zos/rmsportal/JiqGstEfoWAOHiTxclqi.png"
                  />
                }
              >
                <Meta title="动态追踪" description="追踪你关注的动态" />
              </Card>
            </Col>
            <Col xs={24} sm={12} lg={6}>
              <Card
                hoverable
                cover={
                  <img
                    alt="transaction"
                    src="https://gw.alipayobjects.com/zos/rmsportal/JiqGstEfoWAOHiTxclqi.png"
                  />
                }
              >
                <Meta title="交易日历" description="记录重要的交易日期" />
              </Card>
            </Col>
          </Row>
        </div>
      );
    };
    
    export default App;
    

    此代码使用React、Ant Design和TypeScript创建了一个包含搜索框、列表和3个带阴影的卡片的首页样式。列表包括4个项目:我的待办、我的历史、我的关注和我的浏览历史。 卡片分为新闻、动态追踪和交易日历。

    简要解释一下这段代码:

    • 首先,我们从antd中导入所需的组件,如Input,Row, Col, Card, List等,并导入所需的样式。
    • 定义名为App的功能组件
    • 使用Row,Col来放置搜索框并居中。用Search组件创建搜索框
    • 创建一个包含4个项目(我的待办,我的历史,我的关注,我的浏览历史)的列表
    • 接下来,创建了新闻、动态追踪和交易日历3个带阴影的卡片并分别设置其标题和描述
    • Row和Col同时设置响应式布局

    现在,在项目的入口文件index.tsx中渲染App组件:

    import React from 'react';
    import ReactDOM from 'react-dom';
    import App from './App';
    
    ReactDOM.render(<App />, document.getElementById('root'));
    

    这样,你就创建了一个包含搜索框、我的待办、我的历史、我的关注、我的浏览历史以及新闻、动态追踪和交易日历卡片的首页样式。

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.