Skip to content

Plugin: $axios undefined when destructuring Context #554

@malik-steinert

Description

@malik-steinert

Hey Nuxt-Team!

I can't get my head around the following issue. When creating a new plugin in Nuxt 2.15.8, I get the object of type Context injected into the default plugin function like so:

export default function (ctx) {
  // I do something here.
}

I have the nuxt axios package installed, so I could do http requests from my plugin like this:

export default function (ctx) {
  ctx.$axios(someConfig); // works
} 

But, the moment I try to destructure the Context object like this:

export default function ({ $axios }) {
  $axios(someConfig); // undefined
}

$axios is suddenly undefined.

Same behavior when I try to destructure $axios from the app property of Context which was suggested elsewhere.

Thank you for taking the time.

EDIT: I was actually talking about a plugin here, added from a module.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions