Vue3:el-table实现日期的格式化

后端如果返回的是时间戳,需要我们进行日期格式化

例如:2024-09-11T14:19:14

定义一个日期解析的工具组件

javascript 复制代码
export function formatDateAsYYYYMMDDHHMMSS(dateStr: any) {
    const date = new Date(dateStr);
    const year = date.getFullYear();
    const month = String(date.getMonth() + 1).padStart(2, '0');
    const day = String(date.getDate()).padStart(2, '0');
    const hours = String(date.getHours()).padStart(2, '0');
    const minutes = String(date.getMinutes()).padStart(2, '0');
    const seconds = String(date.getSeconds()).padStart(2, '0');
    return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
}

在表格中进行使用该工具完成日期解析

javascript 复制代码
   <el-table-column fixed label="发布时间" width="150">
            <template #default="scope">{{ formatDateAsYYYYMMDDHHMMSS(scope.row.createTime) }}</template>
   </el-table-column>
相关推荐
用户6688599847662 小时前
Vue 3.0安装与使用
vue.js
空中海3 小时前
01 React Native 基础、核心组件与布局体系
javascript·react native·react.js
前端之虎陈随易5 小时前
2年没用Nodejs了,Bun很香
linux·前端·javascript·vue.js·typescript
好运的阿财6 小时前
OpenClaw工具拆解之host_workspace_write+host_workspace_edit
前端·javascript·人工智能·机器学习·ai编程·openclaw·openclaw工具
XiYang-DING6 小时前
JavaScript
开发语言·javascript·ecmascript
空中海7 小时前
02 React Native状态、导航、数据流与设备能力
javascript·react native·react.js
空中海8 小时前
02 状态、Hooks、副作用与数据流
开发语言·javascript·ecmascript
abcnull8 小时前
传统的JavaWeb项目Demo快速学习!
java·servlet·elementui·vue·javaweb
空中海8 小时前
04 React Native工程化、质量、发布与生态选型
javascript·react native·react.js