[Vuejs]-String passed to store action (via mapActions) arrives as [object, Object]

0👍

Try the following, in the child component pass the id as follows:

this.$emit('remove', this.item.id);

Then, the parent renders the child as follows:

<ListItem v-for="item in listItems" :key="item.id" 
          :item="item"
          @remove="deleteListItem"
/>
methods: {
...mapActions('listItems', ['deleteItem',],),
deleteListItem (id) {
     this.deleteItem(id);
},

0👍

It turns out I needed to wrap the argument in an object when I pass it to the store. Doing this.deleteItem({id}); seemed to fix the issue…

0👍

the first argument in vuex actions is the context object. If you don’t want to use it and just use the payload you could use it like this:

deleteItem (_, id) {
  api.del(`${deleteURL}/${id}`);
},

more info about context object

Leave a comment