有很多方法,这里记录下使用dayjs插件处理时间
首先下载这个插件
yarn add dayjs
然后再main.js全局引用下
import relativeTime from 'dayjs/plugin/relativeTime'
import 'dayjs/locale/zh-cn'
const dayjs = require('dayjs')
// 相对时间插件
dayjs.extend(relativeTime)
dayjs.locale('zh-cn')
dayjs().locale('zh-cn').format()
// 全局使用
Vue.prototype.dayjs = dayjs
然后就可以全局使用了,示例如下:
<span>截至{{dayjs(desclist.modifyTime).format('YYYY-MM-DD')}}数据统计</span>
ok完成