Reputation: 33
I want to dispatch dateFor
and ItemsArray
to the action in the store i.e. selectItem
. The code is like this
pushItems: function (dateFor) {
var ItemsArray = this.selectItem
this.$store.dispatch('selectItem', dateFor, ItemsArray)
}
In action of store,
selectItem: function ({ commit }, newDate, newSelectItem) {
var selectNew = {
dateFor: newDate,
ItemsArray: newSelectItem
}
console.log('Check', newDate, newSelectItem)
commit('selectNew', selectNew)
}
But I can only get the value of the first argument passed in the function, in here that is newDate
. I need to be able to pass both the values. Any help would be appreciated !
Upvotes: 1
Views: 42
Reputation: 3972
You could use object destructuring method to pass the values and it should be accurate to get the value based on the key name. see code below
this.$store.dispatch('selectItem',
{
newDate: dateFor,
newSelectItem: ItemsArray
}
)
Then
selectItem: function ({ commit }, {newData, newSelectItem}) {
var selectNew = {
dateFor: newData,
ItemsArray: newSelectItem
}
console.log('Check', newData, newSelectItem)
commit('selectNew', selectNew)
}
Upvotes: 1