Currently, I'm working on an app using Nuxt where I preload some data at nuxtServerInit
and store it successfully. However, as I have multiple projects with similar initial-preload requirements, I thought of creating a reusable module for this logic. The idea was to easily add the module to the nuxt.config.js
in all my other projects to automatically populate the store. But, during the module creation process, I realized that there seems to be no way to access the store at that point. Am I correct in this assumption?
I attempted to use
nuxt.hook('ready', (nuxt) => {...}
, but unfortunately, the nuxt-parameter provided in the callback does not include a reference to the store.
As someone new to Nuxt, I may be missing something crucial or handling my preload issue incorrectly. Is there a better approach to solving this dilemma?
Shown below is my attempt at creating the module named 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