一.目标
把时间转换成'YYYY-MM-DD HH:mm:ss'
查找工具
dayjs第三方库: https://dayjs.fenxianglu.cn/
下载dayjs到工程中 yarn add dayjs
工具函数
因为以后可能也要处理时间, 所以封装个工具函数
在main.js文件中全局注册
import dayjs from 'dayjs'
Vue.prototype.dayjs = dayjs
我这里直接在main.js文件中注册,所以函数直接封装在这里了,大家可以封装一个专门的组件来使用
timeChange(data) {
let time = data //将需要格式化的数据传入
time = this.dayjs(time).format('YYYY-MM-DD HH:mm:ss')
return time
}然后调用该函数,参数是当前需要格式化的时间数据
<template slot-scope="scope">
{{ timeChange(scope.row.addDate) }}
</template>版权声明:本文为chai_tian原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。