react ant add/change created_at

1.引入ant的 Table

复制代码
import { Table, Space, Button, message } from 'antd';

2.获得接口的数据的时候增加上创建时间

复制代码
 const response = await axios.get(`${Config.BASE_URL}/api/v1/calculation_plans?token=${getToken()}`);

      if (response.data.message === 'ok') {

        const data = response.data.data.map((item) => ({

          key: item.id,

          id: item.id,

          name: item.name,

          industry: '-',

          start_year: item.start_year,

          created_at: item.created_at, // 增加创建时间

          end_year: item.end_year,

          calculation_template_name: item.calculation_templates.name,

          year_range: `${item.start_year} - ${item.end_year}`,

        }));

3.对接口的数据进行处理

复制代码
95       {
 96         title: '创建时间',
 97         dataIndex: 'created_at',
 98         key: 'created_at',
 99       },

这样会显示数据:

复制代码
2023-07-24T15:10:38.820628+08:00

需要修改为北京时间:

最后做出这样的修改:(显示为北京时间:2023/7/24 15:10:38)

复制代码
import { Table } from 'antd';

const dataSource = [

  // 数据源

];

const columns = [

  // 其他列配置

  {

    title: '创建时间',

    dataIndex: 'created_at',

    key: 'created_at',

    render: (text) => moment(text).format('YYYY-MM-DD HH:mm:ss'),

  },

];

const MyTable = () => {

  return <Table dataSource={dataSource} columns={columns} />;

};
相关推荐
Hilaku14 小时前
为什么在 2026 年,MPA(多页面应用)正在悄悄复辟?
前端·javascript·程序员
幸福小宝14 小时前
eslint和prettier
前端
anyup14 小时前
终于在今天入选了 Gitee GVP,这真值得庆祝~
前端·uni-app·开源
幸福小宝14 小时前
husky和lint-staged
前端
悟空瞎说14 小时前
iOS 高效绘图
javascript
Slice_cy15 小时前
Mint 自研框架设计与实现:从重复开发走向配置驱动(五)
前端·后端·架构
寒水馨15 小时前
Windows下载、安装 Tailwind CSS-v4.3.3(附安装包tailwindcss-windows-x64.exe)
前端·css·前端开发·tailwind css·utility-first·css 框架·独立 cli
西楼_15 小时前
一文读懂React19究竟更新了什么
前端
四眼肥鱼15 小时前
【Nextjs】macos 系统运行报错:Error: Cannot find module '../lightningcss.darwin-x64.node'
前端·架构·前端框架
hoLzwEge15 小时前
Unplugin Turbo Console:让你的 `console.log` 脱胎换骨
前端·前端框架