Correctly using vuex in custom integration boilerplate

Hello again 🙂

i want to create a vuex store in the custom integration boilerplate. I already have an index.js file inside the stores folder and created a file named
userShipping.js
with following content:

export const state = () => ({
  addresses: []
});

export const getters = {
  getAddress: (state) => (user) => {
    return state.addresses.find(e => e.user === user);
  }
};

export const mutations = {
  addAddress: (state) => (user, address) => {
    // check if user is already in list -> update
    const idx = state.addresses.findIndex(e => e.user === user);
    if (idx === -1) {
      state.addresses.push({user: user, shippingAddress: address});
    } else {
      state.addresses[idx].shippingAddress = address;
    }
  },
  removeAddress: (state) => (user) => {
    const idx = state.addresses.findIndex(e => e.user === user);
    if (idx !== -1) {
      state.list.splice(idx, 1);
    }
  }
};

export const actions = {
  addAddress({commit}, user, address) {
    commit('add', user, address);
  }
};


I know its working, because i can see the store in the vue dev tools. But i can't access and use the actions and mutations...

i tried it with this:

context.root.$store.commit('addAddress', 'testuser', address);


But it does not fire the event.
Do you know how to use a custom store? - am i missing something?
Was this page helpful?