Hello. 👋
I'm trying to achieve a similar goal as described in issue #931.
I would like to have access to the $axios instance from @nuxtjs/axios while lazy-loading the translations - as it is already configured properly to talk with my API.
I visited https://i18n.nuxtjs.org/lazy-load-translations but this example does not mention compatibility with @nuxtjs/axios.
In the file i do this :
export default async ({ $axios }, locale) => {
await $axios.$get('/translations', { params: { locale: locale } })
}
Unfortunately it only find the $axios property on client mode.
This does not work during server first render where context.$axios is undefined.
I get the infamous error we all know in my node process terminal :
ERROR Cannot read property '$get' of undefined
Does someone have any idea how i can get access to the injected $axios instance or is it happening too early ?
I also tried from a different place using the store as an intermediary but got eh same result
export default async ({store}, locale) => {
//await $axios.$get('/translations', { params: { locale: locale } })
await store.dispatch('getTranslations', locale);
}
async getTranslations(ctx, locale) {
return await this.$axios.$get('/translations', { params: { locale: locale } });
},
md5-e6dc916202bdedfb9505710e77f98f32
ERROR Cannot read property '$get' of undefined
Thank you ! Have a good day 🥳
It should work as long as nuxtjs/axios module is registered after the nuxt-i18n module (yes, it's counter-intuitive). If it doesn't then maybe create a repro using the bug report template so that I don't have to.
Hello @rchl 👋
You just blow my mind thank you. 🎉 I was really expecting the module order to work the other way around.
Thanks a lot.
Most helpful comment
It should work as long as
nuxtjs/axiosmodule is registered after thenuxt-i18nmodule (yes, it's counter-intuitive). If it doesn't then maybe create a repro using the bug report template so that I don't have to.