Store
const store = ({
// Create a state with the reactive function we imported previously, this will manage the reactivity for us
state: reactive({
count: null
// If this is null is for the example,
// of course you can initialize the
// counter with 0 directly
}),
// This section will handle the getters
getters: {
getCount() {
return store.state.count
}
},
// This section will manage the changes into the state
mutations: {
incrementCount() {
store.state.count++
}
},
// This section will manage the actions needed for our store
actions: {
initializeCount() {
store.state.count = 0
}
}
})
Vue 3 custom store
Ref: https://dev.to/manuelojeda/learn-to-create-your-custom-global-state-management-with-vue-3-11am