Antd 将TodoList 页面美化一下

Antd 是一个比较好的前端UI框架。

官网:https://ant.design/index-cn

在React 项目中下载,使用 yarn add 命令即可。

使用也很简单。

在组件中引用它的css 样式,然后按需引入即可。

下面贴上代码。

import React, {Component} from 'react';
import 'antd/dist/antd.css';
import { Input, Button, List } from 'antd';

const data = [
  'Racing car sprays burning fuel into crowd.',
  'Japanese princess to wed commoner.',
  'Australian walks 100km after outback crash.',
  'Man charged over missing wedding girl.',
  'Los Angeles battles huge wildfires.',
];

class BeautifulToDoList extends Component {
  render() {
    return (
      <div style={{marginTop: '10px',marginLeft: '10px'}}>
        <Input
          placeholder="todo info"
          style={{width: 300, marginRight: '10px'}}
        />
        <Button type="primary">提交</Button>
        <List
          style={{marginTop: '10px', width: '300px'}}
          bordered
          dataSource={data}
          renderItem={item => (<List.Item>{item}</List.Item>)}
        />
      </div>
    )
  }
}

export default BeautifulToDoList;

然后,轻松的美化了todolist

要将页面中多选的对象传输到后台,可以使用 Ant Design 的 Checkbox 组件和 Form 组件。下面给出一个示例: 1. 在页面中使用 Checkbox 组件,设置 checkboxOptions 和 checkedList 状态: ```jsx import React, { useState } from 'react'; import { Checkbox } from 'antd'; const plainOptions = ['Option 1', 'Option 2', 'Option 3']; const defaultCheckedList = ['Option 1']; function CheckboxGroup() { const [checkedList, setCheckedList] = useState(defaultCheckedList); const onChange = (checkedValues) => { setCheckedList(checkedValues); }; return ( <Checkbox.Group options={plainOptions} value={checkedList} onChange={onChange} /> ); } export default CheckboxGroup; ``` 在这个示例中,我们设置了一个多选框组件,包括了三个选项。默认情况下,第一个选项为选中状态。 2. 在 Form 组件中使用 CheckboxGroup 组件,设置 onFinish 事件: ```jsx import React from 'react'; import { Form, Button } from 'antd'; import CheckboxGroup from './CheckboxGroup'; function CheckboxForm() { const onFinish = (values) => { console.log('Received values of form: ', values); fetch('/api/submit', { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify(values.checkbox), }) .then((response) => response.json()) .then((data) => { console.log('Success:', data); }) .catch((error) => { console.error('Error:', error); }); }; return ( <Form onFinish={onFinish}> <Form.Item name="checkbox"> <CheckboxGroup /> </Form.Item> <Form.Item> <Button type="primary" htmlType="submit"> Submit </Button> </Form.Item> </Form> ); } export default CheckboxForm; ``` 在这个示例中,我们设置了一个表单,包括了多选框组件和提交按钮。当用户点击提交按钮时,会触发 onFinish 事件,该事件会获取表单中勾选的选项,并将其通过网络请求传输到后台。 3. 在后台接收并处理数据。 在这个示例中,我们使用了 fetch 函数来发送网络请求,并在网络请求成功或失败时打印日志。在后台接收到数据后,可以根据具体的业务需求进行处理。 希望这个回答能够帮到你!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值