A small wrapper for integrating dayjs to Vuejs
Dayjs is a minimalist (Fast 2kB) JavaScript library for modern browsers with a largely Moment.js-compatible API. If you use Moment.js, you already know how to use Day.js.
plugins/Dayjs.js
import Vue from 'vue';
import dayjs from 'dayjs';
Object.defineProperties(Vue.prototype, {
$date: {
get() {
return dayjs
}
}
});
main.js
//Plugins
import '@/plugins/Dayjs';
If you need to use an extra plugin from the dayjs library. example
plugins/Dayjs.js
import Vue from 'vue';
import dayjs from 'dayjs';
import relativeTime from 'dayjs/plugin/relativeTime';
dayjs.extend(relativeTime);
Object.defineProperties(Vue.prototype, {
$date: {
get() {
return dayjs
}
}
});
npm install vue-dayjs-plugin
import VueDayjs from 'vue-dayjs-plugin'
Vue.use(VueDayjs)
this.$date('2018-08-08').format('DD/MM/YYYY');
<span> {{ $date('2018-08-08').format('DD/MM/YYYY') }} </span>