Re-exporting all pinia stores from index file #838
-
When using pinia with multiple stores, it becomes somewhat cumbersome to import all these in e.g. components: import { useStore1 } from '@/stores/store-1'
import { useStore2 } from '@/stores/store-2'
import { useStore3 } from '@/stores/store-3'
export default {
setup() {
const store1 = useStore1()
const store2 = useStore2()
const store3 = useStore3()
return { store1, store2, store3 }
},
} Is it possible to re-expose all stores from an index file e.g. import { useStore1, useStore2, useStore3 } from '@/stores'
export default {
setup() {
const store1 = useStore1()
const store2 = useStore2()
const store3 = useStore3()
return { store1, store2, store3 }
},
} |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
It should still work when it comes to codesplit as long as your |
Beta Was this translation helpful? Give feedback.
It should still work when it comes to codesplit as long as your
@/stores/index.ts
file is just doingexport * from './store-1'
for each store. But I would give it a try by using two different stores imported from there in two routes and see if the generated chunks correctl contain only one of them.