Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VueJS how to pass two parameters to an Vuex action

Tags:

vuejs2

vuex

<button class="btn" @click="removeFromTheCart(index,item.price)">
  Remove
</button>

I'm passing two parameters to my action removeFromTheCart.

removeFromTheCart({ commit }, payload) {
  console.log("rooooooohhhhhoooow",payload)

When I console log my payload inside the vuex store it only outputs the index. My second parameter wasn't in the output.

How do I get two parameter values through an action?

like image 990
Pathum Kalhan Avatar asked Apr 24 '18 09:04

Pathum Kalhan


1 Answers

You can send an object as your payload, like this :

<button class="btn" @click="removeFromTheCart({ index, price: item.price })">Remove</button>

And fetch the data in your store :

removeFromTheCart({ commit }, { index, price }) {
  console.log('index', index, 'price', price);
}
like image 87
Thomas Ferro Avatar answered Nov 03 '22 19:11

Thomas Ferro