Vuex - passing multiple parameters to mutation

后端 未结 3 1549
傲寒
傲寒 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:24

    i think this can be as simple let as assume that you are going to pass multiple parameters to you action as you read up there actions accept only two parameters context and payload which is your data you want to pass in action so let take an example

    Setting up Action

    instead of

    actions: {
            authenticate: ({ commit }, token, expiration) => commit('authenticate', token, expiration)
        }
    

    do

    actions: {
            authenticate: ({ commit }, {token, expiration}) => commit('authenticate', token, expiration)
        }
    

    Calling (dispatching) Action

    instead of

    this.$store.dispatch({
                      type: 'authenticate',
                      token: response.body.access_token,
                      expiration: response.body.expires_in + Date.now()
                  })
    

    do

    this.$store.dispatch('authenticate',{
                      token: response.body.access_token,
                      expiration: response.body.expires_in + Date.now()
                  })
    

    hope this gonna help

提交回复
热议问题