How do I set initial state in Vuex 2? | vuex default
IamusingVue.js2.0andVuex2.0forasmallapp.Iaminitializingthethestoreinthecreatedlife-cyclehookontherootVueinstancebycallinganactionthatretrievestheinitialstatefromanAPI....likesoinmyRootComponent:constapp=newVue({el:"#app",router,store,data:{vacation:{},},components:{vacation-status:VacationStatus,},created(){//initializestoredatastructurebysubmittingaction.this.$store.dispatch(getVacation);},computed:{},methods:{}});Thisisworkingjustfine.HereistheactiononmystorethatImcallinghere:getVacation({...
I am using Vue.js 2.0 and Vuex 2.0 for a small app. I am initializing the the store in the created life-cycle hook on the root Vue instance by calling an action that retrieves the initial state from an API....like so in my Root Component:
const app = new Vue({ el: "#app", router, store, data: { vacation: {}, }, components: { vacation-status: VacationStatus, }, created(){ //initialize store data structure by submitting action. this.$store.dispatch(getVacation); }, computed: { }, methods: { } });This is working just fine. Here is the action on my store that Im calling here:
getVacation({commit}){ api.getVacation().then(vacation => commit(UPDATE_VACATION, vacation)) }The mutation that this is committing with UPDATE_VACATION is here:
[UPDATE_VACATION] (state, payload) { state.vacation = payload.vacation; },My Problem: When I load the app, all my components that are getting values from the store...