美文网首页
全局filter

全局filter

作者: 0说 | 来源:发表于2021-04-25 23:26 被阅读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)}`
}

相关文章

网友评论

      本文标题:全局filter

      本文链接:https://www.haomeiwen.com/subject/bpxsrltx.html