Last active
December 18, 2021 18:30
-
-
Save richardpdorr/70b3edda45a3fbe848ef4078c6f7ad2a to your computer and use it in GitHub Desktop.
Extending a base store for Vuex for multiple Vue applications / instances (with some examples).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const changeIsMobile = ({ commit }, isMobile) => { | |
commit('setIsMobile', isMobile); | |
}; | |
export const changeLoading = ({ commit }, loading) => { | |
commit('setLoading', loading); | |
}; | |
export const addError = ({ commit }, e) => { | |
commit('updateAddError', e); | |
}; | |
export const resetAllErrors = ({ commit }) => { | |
commit('resetErrors'); | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as actions from './base-store/actions'; | |
import * as mutations from './base-store/mutations'; | |
import * as getters from './base-store/getters'; | |
export default { | |
state: { | |
loading: false, | |
isMobile: false, | |
errors: [] | |
}, | |
getters, | |
mutations, | |
actions | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const getIsMobile = (state) => { | |
return state.isMobile; | |
} | |
export const getLoading = (state) => { | |
return state.loading; | |
} | |
export const getErrors = (state) => { | |
return state.errors; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const setLoading = (state, loading) => { | |
state.loading = loading; | |
} | |
export const setIsMobile = (state, isMobile) => { | |
state.isMobile = isMobile; | |
} | |
export const updateAddError = (state, error) => { | |
state.errors.push(error); | |
} | |
export const resetErrors = (state) => { | |
state.errors = []; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.... | |
import BaseStore from './path/to/resolve/BaseStore' | |
export const store = new Vuex.Store(Object.assign( | |
{}, | |
BaseStore, | |
{ modules: { exampleModule1, exampleModule2 } } | |
)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment