vue如何使用时间戳?

1.网上找的时间戳方法,我单独放在一个js里


export function formatDate(timestamp) {     

        var date = new Date(timestamp * 1000);//时间戳为10位需*1000,时间戳为13位的话不需乘1000

        Y = date.getFullYear() + '-';

        M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';

        D = date.getDate() + ' ';

        h = date.getHours() + ':';

        m = date.getMinutes() + ':';

        s = date.getSeconds();

        return Y+M+D+h+m+s;

}  

2.在XX.vue组件引入进来


import {formatDate} from '@/assets/js/date.js'

3.为了方便使用,用了过滤器


filters:{

    //时间戳

    formatDate(time) {

        return formatDate(time);

    },

}

4.在列表中使用它(用了elementUI框架)


<el-table-column prop="createTime" label="CREATETIME" sortable>

    <template slot-scope="scope">

        {{ scope.row.createTime|formatDate }}

    </template>

</el-table-column> 

5.执行结果

https://img3.mukewang.com/5ca5b68a0001cf9507810458.jpg

这是怎么回事呀?

LEATH
浏览 5367回答 1
1回答

慕哥6287543

看看scope.row.createTime有没有问题。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript