Having all the stores globally available #1060
-
Hi, Thanks for Pinia. I have a beginner question about best practices / advice; Currently I import the stores in all of my components. import { mapStores } from 'pinia';
import { useJsonStore } from '@/stores/json';
import { useLocationStore } from '@/stores/location'; What would be the best way to prevent repeating these kind of lines in a lot of components? In Vuex you get this.$store, is there an equivalent for Pinia? Or should I think about it a different way... (or is repeating these lines the best way). |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 10 replies
-
Beta Was this translation helpful? Give feedback.
-
Thanks! This is a cool way to remove boilerplate. If I understand it correctly, using this library does the same importing, but hides it from view. So I guess there is nothing inherently wrong or inefficient about doing all those imports, right? |
Beta Was this translation helpful? Give feedback.
-
No need additional modules. Nuxt 3 config:
|
Beta Was this translation helpful? Give feedback.
-
I tried everything but none of them worked, Here is an exampleAdd your stores like code below to
then you can use stores inside any .vue file without importing them. |
Beta Was this translation helpful? Give feedback.
Try this: https://github.com/antfu/unplugin-auto-import.