[Vuejs]-Vue.js how to pass data object to store through an action

-1👍

I have not been able to test this as I am on my tablet, but think what you want is the following. In the calling component:

this.$store.dispatch({
    type: ‘addToCart’,
    row: row
})

In your store actions:

addToCart ({commit, state}, payload) => {
    console.log(`ROW: ${payload.row})
    commit({
        type: ‘mAddToCart’,
        row: payload.row
    })
})

The in your mutations:

mAddToCart((state, payload) => {
    // Do what you need to do with payload.row
})

Hope that helps.

Leave a comment