引入下载的时间
import day.js from ‘dayjs’
加载中文语言包
import ‘dayjs/locale/zh-cn’
引入相对时间处理模块
import rTime from ‘dayjs/plugin/relativeTime’
dayjs.locale(‘zh-cn’)
dayjs.extend(rTime)
处理固定时间格式
export const formatime = (val) =>{
return dayjs(val).format(‘YYYY/MM/DD’)
}
处理相对时间格式
export const relativeTime = time =>{
return dayjs().to(day.js(time))
}
//相应代码块
import dayjs from 'dayjs'
import "dayjs/locale/zh-cn"
import relativeTime from "dayjs/plugin/relativeTime"
dayjs.locale('zh-cn')
dayjs.extend(relativeTime)
export default {
name: 'Home',
filters:{
Time(value){
return dayjs().to(dayjs(value))
}
},
}