// 导入格式化时间的插件
import dayjs from ‘dayjs’
// 导入dayjs中的相对时间的插件
import relativeTime from ‘dayjs/plugin/relativeTime’
// 导入语言包,因为时间插件是英文的
import ‘dayjs/locale/zh-cn’
import Vue from ‘vue’
// 使用相对时间插件relativeTime
dayjs.extend(relativeTime)
dayjs.locale(‘zh-cn’)
// 定义时间过滤器,timefilter是过滤器的名称,谁要用可以直接调用,通过管道符号直接调用即可
Vue.filter(‘timefilter’, function (value) {
return dayjs().from(value)
})
dayjs过滤时间
最新推荐文章于 2023-07-03 10:42:34 发布