main.js에 Vue.filer()을 이용하여 전역으로 설정함
import Vue from 'vue';
import App from './App.vue';
import router from '@/routes/index';
import store from '@/store/index';
import { formatDate } from '@/utils/filters';
Vue.filter('formatDate', formatDate);
Vue.config.productionTip = false;
new Vue({
render: h => h(App),
router,
store,
}).$mount('#app');
filers.js
// 필터 관련 함수가 존재하는 파일
export function formatDate(value) {
const date = new Date(value);
const year = date.getFullYear();
let month = date.getMonth() + 1;
month = month > 9 ? month : `0${month}`;
const day = date.getDate();
let hours = date.getHours();
hours = hours > 9 ? hours : `0${hours}`;
const minutes = date.getMinutes();
return `${year}-${month}-${day} ${hours}:${minutes}`;
}