Handy dayjs(2KB immutable date library alternative to Moment.js) filters and directives for Vue.js
npm install vue-dayjs> Handy Day.js filters and directives for Vue.js
> Day.js 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.
``js
import Dayjs from 'vue-dayjs';
Vue.use(Dayjs, {
// language set, default cn
lang?: cn | en,
/**
* addon filters { key: filter name }
* if set {} will only dayjs base filter can use.
*/
filters?: {
ago: 'ago',
...
},
/**
* addon directives { key: directives name }
* set {} to disable.
*/
directives?: {
countdown: 'countdown',
...
}
});
new Vue({...});
`
Notice this plugin esm format only and it will take effect automatic.
js
{{ someDate | dayjs('YYYY-MM-DD') }}
`$3
`js
{{ someDate | dayjs('add', 1, 'day') }}
`$3
`js
{{ someDate | dayjs('subtract', 1, 'day') }}
`$3
`js
{{ someDate | dayjs('valueOf') }}
`$3
`js
{{ someDate | dayjs('unix') }}
`$3
`js
{{ someDate | dayjs('daysInMonth') }}
`$3
`js
{{ someDate | dayjs('toJSON') }}
`$3
`js
{{ someDate | dayjs('toArray') }}
`$3
`js
{{ someDate | dayjs('toObject') }}
`$3
`js
{{ someDate | dayjs('isLeapYear') }}
`$3
`js
{{ someDate | dayjs('diff', anotherDate) }}
`$3
`js
{{ someDate | ago }}
`$3
`js
`$3
Also can use dayjs in your logic layer.
`js
created() {
this.$dayjs().format('YYYY-MM-DD HH:mm:ss');
}
``