Plugin: `$axios` undefined when destructuring Context
diffetruction opened this issue · comments
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.
That's because the $axios object lives within the context, try to console.log(ctx), you will see the $axios there and other global properties if you set any
@martinsagat, thank you. Yes, I am aware of that and it is the reason why calling ctx.$axios() is working. I have no issues with this particular part. The issue is that with destructuring the Context object, extracting $axios from it, the function seems to "disappear".
Are you able to provide a reproduction?
There is quite a lot of variables in play here. You are saying it has to be a module that provides a plugin and I guess it has to be a javascript plugin?
If you still can reproduce this then feel free to provide a repo that reproduces this issue, including the configuration that you are using.
Will be re-opened if there is more info provided.