Vuex - passing multiple parameters to mutation

后端 未结 3 1552
傲寒
傲寒 2020-12-02 08:53

I am trying to authenticate a user using vuejs and laravel\'s passport.

I am not able to figure out how to send multiple parameters to the vuex mutation via a

3条回答
  •  半阙折子戏
    2020-12-02 09:29

    In simple terms you need to build your payload into a key array

    payload = {'key1': 'value1', 'key2': 'value2'}
    

    Then send the payload directly to the action

    this.$store.dispatch('yourAction', payload)
    

    No change in your action

    yourAction: ({commit}, payload) => {
      commit('YOUR_MUTATION',  payload )
    },
    

    In your mutation call the values with the key

    'YOUR_MUTATION' (state,  payload ){
      state.state1 = payload.key1
      state.state2 =  payload.key2
    },
    

提交回复
热议问题