[Vuejs]-Abstracting component-methods in Component Based frameworks & Redux

0๐Ÿ‘

I face this in my past project and I create 1 function to init state to reduce code repetition:

function initDialogState: () => ({
  isValid: true,
  isVisible: false,
  errorMsg: '',
})

state: {
    items: [
    ],

    dialog: {
      login: initDialogState(),
      signup: initDialogState(),
   }
}

then your mutation can be (I will create an example in Vuex structure):

setDialog(state, { kind, type, value }) {
  Vue.set(state[kind], type, value)
}
๐Ÿ‘คQuoc-Anh Nguyen

Leave a comment