position payload in attribute for action?

Viewed 14

Where I must type 'payload' in attributes for action? In {} brackets or outside? 1 option:

    async loadData( {state, payload, dispatch}) {
      try {
...omitted
        }
      } catch (e) {
        console.error(e)
      }
    },

2 option:

async loadData( {state,dispatch}, payload) {
  try {
    ...omitted
    }
  } catch (e) {
    console.error(e)
  }
},
1 Answers

The first argument can be destructured to access a lot of useful things to access some state, run a quick mutation etc...more details here: https://vuex.vuejs.org/api/#actions

The second argument is the actual payload that you are passing if you want to update something with some data.

Not to confuse with a dispatch where you pass the name + payload directly.

So, option 2.

Related