11. Working with Vuex – Organizing Larger Stores
Activity 11.01: Simplifying a Vuex Store
Solution:
Perform the following steps to complete the activity.
Note
To access the initial code file for this activity, visit https://packt.live/3kaqBHH.
- Begin by creating a new file,
src/store/state.js, that will store the state values for everything but thecatobject:export default { Â Â Â Â name:'Lindy', Â Â Â Â job:'tank', Â Â Â Â favoriteColor:'blue', Â Â Â Â favoriteAnimal:'cat' } - Make a new file,
src/store/getters.js, and move the getter fordesiredPetinto it:export default { Â Â Â Â desiredPet(state) { Â Â Â Â Â Â Â Â return state.favoriteColor + ' ' + state.favoriteAnimal; Â Â Â Â } } - Next, make
src/store/mutations.jsand copy over themutationsnot related to the cat name...