定义全局过滤器
1.根据给定的时间得到一个时间 yyyy-mm-dd hh:mm:ss
2.在 main.js 定义全局过滤器 2.这样每个组件都可以使用全局过滤器了
import Vue from 'vue'
import App from './App.vue'
Vue.filter('dateFormat', function(originVal) {
// 根据给定的时间得到一个时间
const dt = new Date(originVal)
// 年
const y = dt.getFullYear()
// 月份
const m = (dt.getMonth() + 1 + '').padStart(2, '0')
// 日
const d = (dt.getDate() + '').padStart(2, '0')
// 小时
const hh = (dt.getHours() + '').padStart(2, '0')
// 分钟
const mm = (dt.getMinutes() + '').padStart(2, '')
// 秒
const ss = (dt.getSeconds() + '').padStart(2, '0')
return `${y}-${m}-${d} ${hh}:${mm}:${ss}`
})
new Vue({
render: h => h(App)
}).$mount('#app')