Skip to content

Commit

Permalink
fix: add docs for using global moments
Browse files Browse the repository at this point in the history
  • Loading branch information
julon committed Jan 20, 2018
1 parent 0818578 commit 0cee3e9
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
> A Vue.js 2.0 MomentJS library
> It just wired moment api to custom filters in Vue : moment() and duration().
> And also inject moment as this.$moment in your components.
> And also inject moment as **this.$moment** in your components.
> So you have complete access to the whole api of moment in your templates and also the documentation from [momentjs.com](https://momentjs.com/docs).
> Just keep in mind that the left value of the filter is the first argument in any of the moment and duration functions.
> You are good to go now :)
Expand Down Expand Up @@ -84,6 +84,20 @@ Raw JS for moments `moment(Date.now()).format("YYYY")` becomes `Date.now() | mom

Raw JS for duration `moment.duration(500).humanize()` becomes `500 | duration().humanize()`

```js
// in your components
methods: {
now () {
return this.$moment(Date.now()).format()
}
}

// it is also register as a global function in the Vue instance
// so you can do in vuex store or everywhere else to retrieve the same moment instance you initialized
import Vue from 'vue'
const thisYear = Vue.moment(Date.now()).format("YYYY")
```

### Custom moment instances

```js
Expand Down

0 comments on commit 0cee3e9

Please sign in to comment.