Vue 过滤器 Filter传递参数

给日期类型过滤器设置不同格式

  • 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> <!-- 月份简写 天 年 -->
Keep learning
原文地址:https://www.cnblogs.com/leslie1943/p/13417183.html