Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Global locale for moment.js in a vuejs2 project

At the moment in each component I set the locale in each created hook with:

...
created () {
  moment.locale('nl')
}
...

Is this possible to do at one spot that rules for all components?

I'm using the vue webpack template.

like image 835
maartenpaauw Avatar asked Dec 07 '22 17:12

maartenpaauw


1 Answers

In VUE 2.5 can be done like this:

/* IN MAIN FILE */ 
import Moment from 'moment' 
Moment.locale(lang)
Vue.prototype.$moment = Moment
/* INSIDE A COMPONENT */
console.log(this.$moment().format("LL"))
like image 170
Filipe Eusébio Avatar answered Jan 24 '23 04:01

Filipe Eusébio