Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added more guide to using the initialiser plugin #538

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
37 changes: 36 additions & 1 deletion docs/content/en/cookbook/store.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,43 @@ For use with Nuxt, there are few key provisions:
export const plugins = [initializer]
export * from '~/utils/store-accessor'
```

3. You then simply need to add your modules to your store-accessor
```ts{}[utils/store-accessor.ts]
import { Store } from 'vuex'
import { getModule } from 'vuex-module-decorators'
import example from '~/store/example'

let exampleStore: example

3. If you want to access the Nuxt app instance, you will need to do something similar with a plugin, for example:
function initialiseStores(store: Store<any>): void {
exampleStore = getModule(example, store)
}
export { initialiseStores, exampleStore }
```

4. Now you can access stores in a type-safe way by doing the following from a component or page - no extra initialization required.
```ts
import { exampleStore } from '~/store'
//for state
get() {
return exampleStore.exampleState
}
// for getters
someMethod() {
return exampleStore.exampleGetter
}
// for Mutations
someMethod() {
return exampleStore.exampleMutation(payload)
}
// for Actions
someMethod() {
return exampleStore.exampleAction(payload)
}
```

5. If you want to access the Nuxt app instance, you will need to do something similar with a plugin, for example:
```ts{}[plugins/axios-accessor.ts]
import { Plugin } from '@nuxt/types'
import { initializeAxios } from '~/utils/api'
Expand Down