给日期类型过滤器设置不同格式
-
dayjs是一款轻量级的日期操作库 https://day.js.org/en
import Vue from 'vue'
import dayjs from 'dayjs'
// {{ 表达式 | 过滤器 }}
// value: 表达式结果
// format: 格式,默认为 YYYY-MM-DD HH:mm:ss
Vue.filter('date', (value, format = 'YYYY-MM-DD HH:mm:ss') => {
return dayjs(value).format(format)
})
<span class="date">{{article.createdAt | date}}</span> <!-- 默认 -->
<span class="date">{{article.createdAt | date('MMM DD YYYY')}}</span> <!-- 月份简写 天 年 -->
相关文章:
-
2021-10-08
-
2022-02-08
-
2022-02-08
-
2022-12-23
-
2022-12-23
-
2022-12-23
-
2021-11-22
-
2021-07-12