Extending stores #929
Extending stores
#929
-
I was wondering whether it is possible to extend a store. Our scenario. I have an X number of stores, which all share an Y number of options and actions. They also share a few items in the state. |
Beta Was this translation helpful? Give feedback.
Answered by
posva
Dec 31, 2021
Replies: 2 comments 1 reply
-
You would use setup stores + Composables export function useCommonStore() {
const data = ref()
function action() {}
const getter = computed(() => data.value * 2)
return { data, action, getter }
})
export const useStore = defineStore('id', () => {
const { data, action, getter } = useCommonStore()
return { data, action, getter }
}) Here is the Composable approach |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
posva
-
Here's how I did it, not 100% sure if it's the best way but it works for me: The base store that needs to be extended:
An example store that extends the base store:
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You would use setup stores + Composables
Here is the Composable approach