Home

Issue: 2233

[docs] What does inject do?

[issue link]

In docs, inject goes unused:

export default ({ app }, inject) => {
  // Set `i18n` instance on `app`
  // This way we can use it in middleware and pages `asyncData`/`fetch`
  app.i18n = new VueI18n({
    /* `VueI18n` options... */
  })
}
however, it is named in the function signature.

Relese notes for v1.0.0-rc3 say a previous version called injectAs was removed:

  • injectAs has been removed in plugins, you can inject your plugins by accessing app (see example)

It is reintroduced as inject in v1.0.0-rc7

This version is only actually used in one file which is not featured in the examples on the site:
https://github.com/nuxt/nuxt.js/blob/ffe1b6d8dc092f22b45b765f296b0700fd05eae9/examples/with-cookies/plugins/cookies.js#L19

In v1.0.0-rc11 it currently works.

Question

When to use context.app.x = vs inject('x',?

This question is available on Nuxt.js community (#c1961)