'Preloading data to the store at startup in nuxt
I am working on a app with Nuxt and I preload some stuff at nuxtServerInit and put it into the store. That's fine and there is no problem.
I have many more projects with the same kind of initial-preload - so I start thinking that's a good idea to put the logic into a module and all of my other projects can just add the module to the nuxt.config.js and the store will be prefilled... I started creating the module and find out, that there is no way to reach the store at this point, am I right?
I tried nuxt.hook('ready', (nuxt) => {...} but the nuxt-parameter from the callback doesn't have a store reference.
I am new at Nuxt and maybe I miss some point or handle my preload-issue the wrong way?
Here is my modules/mymodule.ts
const mymodule: Module<Options> = function (moduleOptions: Options) {
const { nuxt } = this
nuxt.hook('ready', async (__nuxt: any) => {
// __nuxt ... no store reference :(
})
}
export default mymodule
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
