Home > Software engineering >  Dispatch method does not pass a variable to store
Dispatch method does not pass a variable to store

Time:01-05

I want to hand over variable from my component to store. In component methods i write:

 methods:{
    push(){
        let message = "hi"
        this.$store.dispatch('test', message)
    }
 }

Then in index.js:

actions: {
  test({dispatch},{test}){
    console.log(test)
  },}

And in console i have - undefined

CodePudding user response:

You shouldn't destruct the dispatch payload {test} unless the message parameter has a field called test:

actions: {
  test({dispatch},test){
    console.log(test)
  },}
  •  Tags:  
  • Related