[Vuejs]-How can i use vue-moment ( this.$moment) in Vuex?

3👍

You can just use moment in the Vuex by added it, in your store.js file.

import moment from "moment";

And then you can use it, in your actions and etc.
Take a look at my example here

2👍

You do not have a reference to this when trying to create a Vuex store.

You can just add a reference to the import like this:

import moment from 'moment'
export default new Vuex.Store({ moment : moment})

2👍

You don’t need to use moment by this.$moment, simply you need to install the moment via npm and tell Vue to use it globally

install

$ npm install vue-moment

To tell vue to use it globally

Vue.use(require('vue-moment'));

and then you can simply use moment("dddd, MMMM Do YYYY, h:mm:ss a") in any component.

Check the docs here

1👍

Try this Vue.prototype.$moment in Vuex file.

Leave a comment