[Vuejs]-Vuex-map-fields updating multiple stores through modules

10šŸ‘

Iā€™m the creator of vuex-map-fields, the Author asked the same question on GitHub:

Instead of passing multiple getters to createHelpers(), you can destructure and rename the return value of createHelpers() and call it twice.

const { mapFields: mapKitchenFields } = createHelpers({
  getterType: 'getKitchenField',
  mutationType: 'updateKitchenField',
});
const { mapFields: mapApplicantFields } = createHelpers({
  getterType: 'getApplicantField',
  mutationType: 'updateApplicantField',
});

export default {
  computed: {
    ...mapKitchenFields(['no_panels']),
    ...mapApplicantFields(['firstName', 'lastName']),
  },
}

If the desctructuring syntax is new to you, you can read more about it from Wes Bos: https://wesbos.com/destructuring-renaming/

šŸ‘¤moriartie

Leave a comment