date-format.js 565 B

123456789101112131415161718192021222324252627
  1. import DateKit from '@/utils/date-kit'
  2. const dateFilter = {
  3. /**
  4. * 功能描述:格式化时间字段
  5. * 使用方式:
  6. * {{item.date | fmtDate}}
  7. * {{row.createAt | fmtDate('yyyy-MM-dd')}}
  8. * @param value
  9. * @param format
  10. * @returns {*}
  11. */
  12. formatDate (value, format = 'yyyy-MM-dd HH:mm:ss') {
  13. if (!value) {
  14. return ''
  15. }
  16. return DateKit.format(new Date(Date.parse(value.replace(/-/g, '/'))), format)
  17. },
  18. // 全局安装器
  19. install (Vue) {
  20. Vue.filter('fmtDate', this.formatDate)
  21. }
  22. }
  23. export default dateFilter