Home

Issue: 1697

Unable to access Vue instance properties in asyncData

[issue link]

Using the instance properties approach in a plugin, and after registering that plugin in nuxt.config.js, I’m unable to access those properties in asyncData:

export default {
  async asyncData({ app }) {
    console.log(app.$myVar); // === undefined
    return {};
  }
}

Probably related, I can’t access any $variables on app. Here is what app consists of:

// console.log(Object.keys(app));
[ 'router',
  'store',
  '_nuxt',
  'head',
  'data',
  'beforeCreate',
  'created',
  'mounted',
  'watch',
  'methods',
  'components',
  'render',
  'staticRenderFns',
  '_ssrRegister',
  '__file' ]

But of course, the context docs say I should be able to.

The root vue instance that includes all your plugins. For example, when using axios, you can get access to axiosthroughcontext.app.axios through context.app.axios

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