I have a nice mutation JS file like this.
export default {
UPDATE_DATA: (state, data, meta) => {
state.dataTable = data;
if (meta === undefined)
return;
state.activeDataRow = meta;
}, ...
}
It's being called by to different actions in the following ways.
contextmit("UPDATE_DATA", Map.table(payload.type, data));
contextmit("UPDATE_DATA", Map.table(payload.type, data), meta);
I've checked the meta being sent in the action and it's definitely not undefined. However, when I check the meta in the mutation, it is! Why? How do I kill this problem?
I have a nice mutation JS file like this.
export default {
UPDATE_DATA: (state, data, meta) => {
state.dataTable = data;
if (meta === undefined)
return;
state.activeDataRow = meta;
}, ...
}
It's being called by to different actions in the following ways.
context.mit("UPDATE_DATA", Map.table(payload.type, data));
context.mit("UPDATE_DATA", Map.table(payload.type, data), meta);
I've checked the meta being sent in the action and it's definitely not undefined. However, when I check the meta in the mutation, it is! Why? How do I kill this problem?
Share Improve this question edited Dec 18, 2016 at 0:47 Saurabh 73.7k44 gold badges191 silver badges251 bronze badges asked Dec 17, 2016 at 18:33 Konrad VilterstenKonrad Viltersten 39.3k85 gold badges287 silver badges509 bronze badges1 Answer
Reset to default 8What vuex docs suggests is to send a payload in the second argument.
In most cases, the payload should be an object so that it can contain multiple fields, and the recorded mutation will also be more descriptive:
So you can call it like this with payload:
context.mit("UPDATE_DATA", {data: Map.table(payload.type, data), meta: meta});
and your mutation will look like following:
export default {
UPDATE_DATA: (state, payload) => {
state.dataTable = payload.data;
if (payload.meta === undefined)
return;
state.activeDataRow = payload.meta;
}, ...
}
There is an alternet way to calling mutations as well which is called Object-Style Commit. You can pass an object in mit, with type as mutation name, like following:
context.mit({
type:: "UPDATE_DATA",
data: Map.table(payload.type, data),
meta: meta
});