ant

ant

使用React+Antd遇到的Table组件时间格式化的问题

我在开发react项目时使用antdUI进行开发,遇到了对时间格式化的问题,下面是我成功格式化的解决办法

在使用antd的时候要想修改table里面的内容需要用到render属性

 这里使用的moment 。使用前请先安装 yarn add moment 

代码如下

// 我这边是hooks
import moment from 'moment';
export default (props: any) => {const formatterTime = (val) => {return val ? moment(val).format('YYYY-MM-DD HH:mm:ss') : '';};const columns: any = [{title: `${entryName}`,dataIndex: 'projectName',key: 'projectName',ellipsis: true,},{title: `${t('created-by')}`,dataIndex: 'creatorName',key: 'creatorName',ellipsis: true,},{title: `${creationTime}`,dataIndex: 'created',key: 'created',ellipsis: true,render: formatterTime, //在这里调用就可以实现时间格式化},{title: `${type}`,dataIndex: 'status',key: 'status',render: (text) => (<span>{/* 0 已发布,1 待审核,2 已退回*/}{text == '0'? `${t('published')}`: text == '1'? `${t('pending-approval')}`: `${t('returned')}`}</span>),},{title: `${t('bottom-operation')}`,dataIndex: 'operation',key: 'operation',align: 'center',width: 280,render: (_, record) => (<Space size="middle"><a className="see border_bottom">{t('pass')} </a><a className="close border_bottom">{t('return')}</a><a className="see border_bottom" onClick={() => onSee(record)}>{t('see')}</a><a className="close border_bottom">{t('close')}</a><aclassName="codeWord border_bottom"onClick={() => onPasswordSet(record)}>{t('password-set')}</a></Space>),},];
}

 

发布者:admin,转转请注明出处:http://www.yc00.com/news/1689383657a239537.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信