全局filter

2021-04-25  本文已影响0人  0说

nuxt.config.js

 plugins: [
    '~/plugins/router.js',
    // 配置拦截器
    {
      src: '~/plugins/axios',
      ssr: true // 开启服务端渲染
    },
    {
      src: '~/plugins/element-ui',
      ssr: true, //不支持服务端渲染不要给true
      // mode: 'server' // 模式服务端
    },
    '~/plugins/global'
  ],

global.js

import Vue from 'vue'

import * as filters from '../assets/script/filter'

Object.keys(filters).forEach(key => Vue.filter(key, filters[key]))

filter

export const makeUpZero = (num) => {
  return num < 10 && '0' + num || num + ''
}

export const formatDate = (time) => {
  let _d = new Date()
  _d.setTime(time)

  let year = _d.getFullYear()
  let month = _d.getMonth() + 1
  let date = _d.getDate()
  let hour = _d.getHours()
  let min = _d.getMinutes()
  let sec = _d.getSeconds()

  return `${year}年${makeUpZero(month)}月${makeUpZero(date)}日 ${makeUpZero(hour)}:${makeUpZero(min)}:${makeUpZero(sec)}`
}

上一篇 下一篇

猜你喜欢

热点阅读