Mutations expect two arguments: state
and payload
, where the current state of the store is passed by Vuex itself as the first argument and the second argument holds any parameters you need to pass.
The easiest way to pass a number of parameters is to destruct them:
1 2 3 4 5 6 | mutations: { authenticate(state, { token, expiration }) { localStorage.setItem('token', token); localStorage.setItem('expiration', expiration); } } |
Then later on in your actions you can simply:
1 2 3 4 | store.commit('authenticate', { token, expiration, }); |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.