vue3.0 时间戳转时间

由于 3.0 移除了2.0 的 filters 后,

所以在3.0中,设置:

<script lang="ts">
    export default defineComponent({
        name: "Home",
        setup() {
            // 时间戳转时间
            function formatDate(value: string|number|Date) {
                let date = new Date(value);
                let y = date.getFullYear();
                let MM = date.getMonth() + 1 as number;
                MM = MM < 10 ? ('0'+MM) as unknown as number : MM;
                let d = date.getDate();
                d = d < 10 ? ('0' + d) as unknown as number : d;
                let h = date.getHours();
                h = h < 10 ? ('0' + h) as unknown as number : h;
                let m = date.getMinutes();
                m = m < 10 ? ('0' + m) as unknown as number : m;
                let s = date.getSeconds();
                s = s < 10 ? ('0' + s) as unknown as number : s;
                return y + '-' + MM + '-' + d + ' ' + h + ':' + m + ':' + s;
            };
    }
    return{ formatDate,
    } });
</script>

 

<template>
    <el-table
                :data="tableData"
                style="width: 100%"
                :fit="true"
                @selection-change="handleSelectionChange"
                row-key="id"
                :header-cell-style="{background:'#F5F6FA',color:'#585858',textAlign: 'center',fontSize: '12px'}">
                <el-table-column
                    prop="createTime"
                    label="导入时间"
                    align="center"
                    min-width="160"
                    show-overflow-tooltip
                >
                    <template v-slot="scope">
                        <span v-if="scope.row.createTime !== null">{{formatDate(scope.row.createTime)}}</span>
                    </template>
                </el-table-column>
</template>

 

posted @ 2021-08-11 15:28  小蘑菇123  阅读(1250)  评论(0编辑  收藏  举报