I want to put the momentJS library in my Vue application, and that the full functionality of moment is available in any component of my app.
I want to put the momentJS library in my Vue application, and that the full functionality of moment is available in any component of my app.
To 'install' moment.js in your Vue app we do the following:
// main.js
import Vue from 'vue'
import moment from 'moment'
import App from './App'
...
Object.defineProperty(Vue.prototype, '$moment', {value: moment})
With this we already have access to momentum in our components in this way:
this.$moment()
Example, in our App.vue file
const date = "21/01/2018"
const format = "DD/MM/YYYY"
this.$moment(date, format).isValid()
Edit :
As Pablo says in the comment below, this can be used with other libraries, for example lodash