D
D
Dmitry Petrik2017-07-05 07:29:23
JavaScript
Dmitry Petrik, 2017-07-05 07:29:23

How to pass multiple parameters to an action in Vue(vuex)?

I want to pass several parameters to the action (vuex) when the event is triggered: I.e. I pass the event itself and another task object. The action itself looks like this:
<div @dragstart="dragStart($event, task)"></div>

dragStart({state, commit, getters}, event, task) {
    commit(mutations.START_DRAG, {state, getters, event, task});
  },

If I look at what is passed to the action, then everything is passed to the event correctly, the event. And here is task in action with the value undefined. Those. It turns out that only one parameter is passed in the event. How to pass multiple parameters? I found a temporary solution for myself to pass parameters in an array . But these are some kind of crutches. Who faced it?
<div @dragstart="dragStart([$event, task])"></div>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nikolay Semenov, 2017-07-05
@Flexo

<div @dragstart="dragStart({$event, task})"></div>
dragStart({state, commit, getters}, {event, task}) {
    commit(mutations.START_DRAG, {state, getters, event, task});
  },

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question