viewui的table格式化显示日期

本文介绍了如何在Vue项目中结合Element-UI,利用moment.js库对表格中的日期进行格式化显示,包括下载引入moment.js,组件中的处理方法及实际显示效果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

下载 moment.js

npm install moment --save

引入 moment.js

在这里插入图片描述

import Moment from 'moment'
Vue.prototype.moment = Moment

组件中

表格部分代码

<Table size="small" border stripe :columns="orderColumns" :data="orderList" style="border-radius: 3px;">
      <template slot-scope="{ row, index }" slot="action">
        <Button type="primary" size="small" style="margin-right: 5px" @click="handleEdit(index)">编辑</Button>
        <Button type="error" size="small" @click="handleDelete(row, index)">删除</Button>
      </template>
    </Table>

表格的列对应的代码

orderColumns: [
        {
          title: '日期',
          key: 'billingDate',
          width: '120px',
          align: 'center',
          render: (h, params) => {
            return h('span', {
            }, this.dateFormat(params.row.billingDate))
          }
        }
 ]

在methods 中定义 dateFormat方法

	// 日期时间格式化
    dateFormat (date) {
      var result = this.moment(date).format('YYYY-MM-DD')
      return result
    }

显示效果

在这里插入图片描述

参考文章

vue+element-ui 表格中的时间格式化

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值