Skip to content

Commit 0cee3e9

Browse files
committed
fix: add docs for using global moments
1 parent 0818578 commit 0cee3e9

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

README.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
> A Vue.js 2.0 MomentJS library
1414
1515
> It just wired moment api to custom filters in Vue : moment() and duration().
16-
> And also inject moment as this.$moment in your components.
16+
> And also inject moment as **this.$moment** in your components.
1717
> 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).
1818
> Just keep in mind that the left value of the filter is the first argument in any of the moment and duration functions.
1919
> You are good to go now :)
@@ -84,6 +84,20 @@ Raw JS for moments `moment(Date.now()).format("YYYY")` becomes `Date.now() | mom
8484

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

87+
```js
88+
// in your components
89+
methods: {
90+
now () {
91+
return this.$moment(Date.now()).format()
92+
}
93+
}
94+
95+
// it is also register as a global function in the Vue instance
96+
// so you can do in vuex store or everywhere else to retrieve the same moment instance you initialized
97+
import Vue from 'vue'
98+
const thisYear = Vue.moment(Date.now()).format("YYYY")
99+
```
100+
87101
### Custom moment instances
88102

89103
```js

0 commit comments

Comments
 (0)