Can't Send In A Second Parameter To The Mutation In Vue Store
I have a nice mutation JS file like this. export default { UPDATE_DATA: (state, data, meta) => { state.dataTable = data; if (meta === undefined) return; st
Solution 1:
What 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.commit("UPDATE_DATA", {data: Map.table(payload.type, data), meta: meta});
and your mutation will look like following:
exportdefault {
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 commit, with type as mutation name, like following:
context.commit({
type:: "UPDATE_DATA",
data: Map.table(payload.type, data),
meta: meta
});
Post a Comment for "Can't Send In A Second Parameter To The Mutation In Vue Store"