[云开发5]-通过React+Boostrap快速构建一个卡片应用

React

React,目前非常流行的前端框架之一。采用声明式的设计,高效,灵活。

Bootstrap

在这里插入图片描述

Bootstrap,来自 Twitter,是目前最受欢迎的前端框架。Bootstrap 是基于 HTML、CSS、JAVASCRIPT 的,它简洁灵活,使得 Web 开发更加快捷。

Bootstrap中包含了丰富的Web组件,根据这些组件,可以快速的搭建一个漂亮、功能完备的网站,其中包括以下组件:
下拉菜单、按钮组、按钮下拉菜单、导航、导航条、路径导航、分页、排版、缩略图、警告对话框、进度条、媒体对象等

项目设计

  • 通过服务器获取一些待办事项,然后通过漂亮的卡片设计来显示。
  • 支持多端设备。

项目开发

  1. 数据通过JSON来模拟后端获取的数据:
{
"todos": [
    {
        "title": "Reading",
        "date": "2020-02-01",
        "description": "fdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfd"

    },
    {
        "title": "Coding",
        "date": "2020-02-03",
        "description": "fdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfd"

    },
    {
        "title": "Running",
        "date": "2020-02-04",
        "description": "fdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfd"

    },
    {
        "title": "Party",
        "date": "2020-02-05",
        "description": "fdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfd"

    },
    {
        "title": "Sleep",
        "date": "2020-02-06",
        "description": "fdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfdfd"

    }
]
}
  1. 创建React项目:
    通过create react app创建app。

内容比较简单,将数据通过Card显示:

创建一个页面的Component,Contents.js:


import React, { Component } from 'react';
import { todos } from './todos.json';

export default class Content extends Component {
    render() {
        return (
            <main role="main" class="container">

                <div class="row">


                    {todos.map(
                        todo => {
                            return (
                                <div class="col-sm-12 col-md-4">

                                    <div class="card mb-3">
                                        <div class="card-body">
                                            <h5 class="card-title">{todo.title}</h5>
                                            <h6 class="card-subtitle mb-2 text-muted">{todo.date}</h6>
                                            <p class="card-text">{todo.description}</p>
                                            <a href="#" class="card-link">link</a>
                                            <a href="#" class="card-link">Another link</a>
                                        </div>
                                    </div>

                                </div>
                            )
                        }
                    )}


                </div>


            </main>
        );
    }
}

  1. 引入Bootstrap

这里是通过CSS的方式引入了bootstrap,在index.html中加入bootstrap的css和js文件:

  <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css"
    integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
  <script src="https://code.jquery.com/jquery-3.4.1.slim.min.js"
    integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n"
    crossorigin="anonymous"></script>
  <script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js"
    integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo"
    crossorigin="anonymous"></script>
  <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"
    integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6"
    crossorigin="anonymous"></script>

测试运行

本地运行:

npm start

在这里插入图片描述
Bootstrap还提供了响应式的交互,在移动端也能方便查看:

小结

React使用JSX,JSX是JS语法的扩展,看起来和HTML比较像,比较推荐的写法。通过React构建组件,使代码更加容易得到复用。

Bootstrap作为最受欢迎的CSS库,可以非常方便的快速构建一个美观的应用。

项目代码

参考阅读

  • https://reactjs.org/
  • https://github.com/twbs/bootstrap
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
使用React和Ant Design来实现一个用户管理功能非常简单。首先,我们需要创建一个React应用程序。可以使用脚手架工具(如Create React App)来快速搭建起一个React应用的基本结构。 1. 创建React应用程序 使用以下命令来创建一个新的React应用程序: ``` npx create-react-app user-management cd user-management ``` 2. 安装Ant Design 在项目根目录下运行以下命令来安装Ant Design依赖项: ``` npm install antd ``` 3. 集成Ant Design组件 编辑src/App.js文件,导入所需的Ant Design组件并编写用户管理功能的代码。以下是一个简单的示例: ```jsx import React, { useState } from 'react'; import { Table, Button, Modal, Form, Input } from 'antd'; const App = () => { const [users, setUsers] = useState([]); const [isModalVisible, setIsModalVisible] = useState(false); const columns = [ { title: '姓名', dataIndex: 'name', key: 'name' }, { title: '年龄', dataIndex: 'age', key: 'age' }, { title: '操作', key: 'action', render: (text, record) => <Button onClick={() => deleteUser(record.key)}>删除</Button> } ]; const [form] = Form.useForm(); const addUser = () => { form.validateFields().then(values => { const user = { name: values.name, age: values.age, key: users.length + 1 }; setUsers([...users, user]); form.resetFields(); setIsModalVisible(false); }); }; const deleteUser = (key) => { setUsers(users.filter(user => user.key !== key)); }; return ( <div> <Button onClick={() => setIsModalVisible(true)}>添加用户</Button> <Table dataSource={users} columns={columns} /> <Modal title="添加用户" visible={isModalVisible} onCancel={() => setIsModalVisible(false)} onOk={addUser}> <Form form={form}> <Form.Item name="name" label="姓名" rules={[{ required: true }]}> <Input /> </Form.Item> <Form.Item name="age" label="年龄" rules={[{ required: true }]}> <Input /> </Form.Item> </Form> </Modal> </div> ); }; export default App; ``` 4. 运行应用 使用以下命令来运行应用程序: ``` npm start ``` 应用程序将在浏览器中自动打开。您现在就可以通过点击“添加用户”按钮来添加用户,点击“删除”按钮来删除用户,并且可以通过Ant Design的Table组件来显示用户列表。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值