Skip to content

How to access Pinia outside of Vue component, in Vue app #687

Discussion options

You must be logged in to vote

No you do not import the App again. You would simply import the store you want to use with something like import { useCounterStore } from '@/stores/counter' and then call const counterStore = useCounterStore() WITHIN the interceptor (of course, replace with the actual name of your store).

You can then change the state, call actions etc. from within the interceptor. It's important you call the store within the interceptor because if you do it outside then Pinia may not have initialised yet and you will get a console warning/error.

This is all well documented at https://pinia.esm.dev/core-concepts/outside-component-usage.html#using-a-store-outside-of-a-component

Replies: 3 comments 7 replies

Comment options

You must be logged in to vote
4 replies
@iknowmagic
Comment options

@BenShelton
Comment options

@iknowmagic
Comment options

@BenShelton
Comment options

Answer selected by iknowmagic
Comment options

You must be logged in to vote
3 replies
@BenShelton
Comment options

@sheldonstewart
Comment options

@sheldonstewart
Comment options

Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
4 participants