I have my own NuxtJS module which registeres my own plugin like so:
import path from 'path'
export default function (moduleOptions) {
const { nuxt } = this
this.addPlugin({
src: path.resolve(__dirname, 'src/plugins/auth.js'),
options: Object.assign({}, nuxt.options.pauth, moduleOptions)
})
}
The problem shows up when I try to access $axios within plugin registered via module. Does anyone know how to make it work?
export default({ $axios, store }, inject) => {
store.registerModule('auth', authModule, { preserveState: !!store.hasModule('auth') })
inject('auth', new AuthService(store, '<%= JSON.stringify(options) %>'))
//
//
//
// console.log(app.$axios, 'robert')
// $axios.onRequest(config => {
// console.log('config')
// })
// app.router.beforeEach(async (to, from, next) => {
// await store.restored
// next()
// })
}
So $axios is undefined but store is there. The context when logged in console or normal plugin defined outside of my module has access to $axios.
It is clearly to do with order and timing. Does anyone know how to deal with that? My plugin lives in my module.