How to initialise a store, pre vue build #512
Answered
by
posva
bobmcallan
asked this question in
Help and Questions
-
I'm using Vue 3 with composition API for majority of components/views. I'd like to understand how it is possible to initialise a store when the Vue application is created. My scenario is simple:
I've used Vuex to initialise in const app = createApp({ created() { this.$store.dispatch("userinit"); } }) . However as the Pinia stores are not initialised globally @startup, rather only when added to a component (?) I don't know how to implement this logic. How to achieve? Bob |
Beta Was this translation helpful? Give feedback.
Answered by
posva
May 31, 2021
Replies: 1 comment 1 reply
-
You can do const app = createApp({
setup() {
const store = useGlobalStore()
store.userInit()
}
}) this is equivalent to what you were doing in Vuex: const app = createApp({ created() { this.$store.dispatch("userinit"); } }) |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
posva
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can do
this is equivalent to what you were doing in Vuex: