后端返回的时间数据格式为:
2022-07-05T09:57:39.000Z
需要格式化为:
2018-08-07 00:00:00
解决方法:
安装dayjs包
npm install dayjs -s
在需要格式化时间的页面引入,也可以全局引入,我这里在单页面引入:
import dayjs from "dayjs"
在methods中写一个转换方法:
methods:{
timeTranslate (val) {
return dayjs(val).format('YYYY-MM-DD HH:mm:ss')
},
}
这里我是放在el-table中显示的
<el-table-column label="协议创建时间" align="center" prop="createdAt" width="200%">
<template slot-scope="scope">
{{timeTranslate(scope.row.createdAt)}}
</template>
</el-table-column>
成功显示