-
Notifications
You must be signed in to change notification settings - Fork 121
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"ReferenceError: moment is not defined" #136
Comments
It seems that this package is not working as intended. I followed @michealjroberts advice and went back to using vanilla moment.js. At least now I can return some formatted timestamp. |
The moment instance is added to the prototype of a Vue and so can be accessed like this in your Vue component. methods : {
date(timestamp) {
return this.$moment( timestamp )
}
} This is explained at the bottom of the readme and should still be working as intended. But if all you need is to return some formatted timestamps and not use any of the additional filter functionality, it sounds like using vanila moment.js will probably work best for you. |
I suggest you update the usage examples at the beginning of the doc, which currently only explains |
Ok, thanks for the suggestion. I would say though this package was built to provide "Handy Moment.js filters for your Vue.js project" (the first line of the readme) and as filters are exclusively used within the The use case that you have is covered by this package but as you say, this package wouldn't offer any more value than using vanilla The reason that I pointed to the docs was in response to your line...
... as the code I provided is the intended and documented behaviour and anyone stumbling across this issue would be directed to the correct place. |
In light of what you mention above, how would I refactor the following code to work in a component:
|
Sorry I wasn't sure which part of the thread you were referring to, so I have answered from a couple of different perspectives. Using vue-moment For your example above, this should do the trick... this.$moment(this.marker.created_at).format('dddd, MMMM Do YYYY') Vanilla moment.js import moment from 'moment' and then you can use moment methods in that component moment(this.marker.created_at).format('dddd, MMMM Do YYYY') I hope that helps. |
I don't think so. After I registered the moment: import VueMoment from "vue-moment";
Vue.use(VueMoment); In the following method methods: {
onSelect(selected: any) {
this.message = this.$moment().locale() + " " + "Selected";
console.log(selected);
}, I have the following error:
If I type This plugin is not working as expected. |
Is this a type error, as opposed to a runtime error? |
I guess it's a TS error (build error). I found there is @types/vue-moment which enables types. If this module can provide |
Thank you a lot. 👍 Please feel free to close the issue. |
I'm wondering how people are getting this to work. I am building an app with Laravel and Vue.
In my
app.js
I import Moment:Then in my component:
Which results in:
"ReferenceError: moment is not defined"
I also tried
Vue.use(require('vue-moment'));
and different combinations of upper/lowercase. Any clue?The text was updated successfully, but these errors were encountered: