在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/HTML5  HTML/ vue如何使用時(shí)間戳?

vue如何使用時(shí)間戳?

1.網(wǎng)上找的時(shí)間戳方法,我單獨(dú)放在一個(gè)js里

export function formatDate(timestamp) {     
        var date = new Date(timestamp * 1000);//時(shí)間戳為10位需*1000,時(shí)間戳為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組件引入進(jìn)來

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

3.為了方便使用,用了過濾器

filters:{
    //時(shí)間戳
    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.執(zhí)行結(jié)果

clipboard.png

這是怎么回事呀?

回答
編輯回答
胭脂淚

看看scope.row.createTime有沒有問題。

2017年10月25日 06:23