nuxt-community / moment-module

Efficient Moment.js integration for Nuxt
MIT License
195 stars 12 forks source link

Cannot read property '$moment' of undefined #14

Closed blackinitial closed 5 years ago

blackinitial commented 5 years ago

how to use nuxt moment?

i was added nuxt moment on module nuxt.config.js and i try to call moment on mounted() a page but has undefined $moment.

nuxt.config.js

modules: [
    ...
    '@nuxtjs/moment',
    ...
  ],

pages

mounted() {
    console.log(this.$moment) // undefined $moment
  },
teledirigido commented 5 years ago

Make sure you did installed Nuxt Moment: yarn add moment @nuxtjs/moment OR npm i moment @nuxtjs/moment

blackinitial commented 5 years ago

@teledirigido i was installed @nuxtjs/moment and moment

ricardogobbosouza commented 5 years ago

@blackinitial I could not reproduce. Share your setup

blackinitial commented 5 years ago

@ricardogobbosouza i use default setup from fresh nuxtjs . Only add moment on modules nuxt.config.js

ricardogobbosouza commented 5 years ago

@blackinitial Try re-install dependencies

ricardogobbosouza commented 5 years ago

@blackinitial it worked?

blackinitial commented 5 years ago

I canceled using this library, I was removed. Finally, I implement moment with plugin methods nuxt js.

ricardogobbosouza commented 5 years ago

@manniL , @pi0 This can also be closed, this error no longer exists

orange181 commented 5 years ago

Hi!

After getting this error with all my modules, i upgrade my version of npm and now it's working I hope this can be helpful !

(same for yarn if you using it)

PayteR commented 5 years ago

same error here, when i call function in template

{{ $moment(post.post_date).format('HH:mm') }} // works well

it works just fine, when it's used in mounted() it's fine too

  mounted: function() {
    console.log(this.$moment) // works well
  },

but when i want to use it in apollo query variable, then it's undefined

apollo: {
    posts: {
      query() {
        return POSTS_QUERY
      },
      update: data => data.postsElastic,
      variables() {
        // Use vue reactive properties here
        return {
          date_after: this.$moment().format() // undefined
        }
      }
    }
  }