Skip to content
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

Can't use in plugin #4

Closed
rktyt opened this issue Sep 10, 2018 · 0 comments · Fixed by #8
Closed

Can't use in plugin #4

rktyt opened this issue Sep 10, 2018 · 0 comments · Fixed by #8

Comments

@rktyt
Copy link

rktyt commented Sep 10, 2018

nuxt.config.js

  ...
  modules: [
    '@nuxtjs/axios',
    ['@nuxtjs/moment', ['ja']]
  ],
  plugins: [
   ...
    '~/plugins/formatter.js',
   ...
  ],
  ...

~/plugins/formatter.js

export default ({ app }, inject) => {
  inject('versionFormat', (date) => app.$moment(date).format('YYYY/MM/DD HH:mm:ss.SSS'))
}

The above code doesn't work because app.$moment is undefined.
Maybe same as #3.


I want you to change it like @nuxtjs/axios module.

https://github.com/nuxt-community/moment-module/blob/master/lib/moment.plugin.js

-import Vue from 'vue'
import moment from 'moment'

<%= options.locales.map(l => `import 'moment/locale/${l}'`).join('\n') %>

-if (!Vue.prototype.hasOwnProperty('$moment')) {
-  Object.defineProperty(Vue.prototype, '$moment', {
-    get() {
-      return moment
-    }
-  })
-}
+export default (ctx, inject) => {
+  ctx.$moment = moment
+  inject('moment', moment)
+}

*** Sorry, not tested.**

@manniL manniL mentioned this issue Dec 5, 2018
@pi0 pi0 closed this as completed in #8 Dec 10, 2018
pi0 added a commit that referenced this issue Dec 10, 2018
- Use inject
- Update deps
- Add defaultLocale option

Resolves #6
Resolves #5
Resolves #4
Resolves #3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant