Accessing to state object property from mutations
up vote
0
down vote
favorite
I'm trying to access a state object property from a mutation in a Vuex Store but I can't find the right syntax :
Here is the state:
state:
events: [
day: 8
location: NY
,
day: 9:
location: NY
]
And here is the mutation :
SET_EVENT_LIST: (state, list) =>
if(list.day < 10)
list.day = '0'+list.day
state.events = list
,
I want to change the value of each event.day
under 10. What am I doing wrong?
javascript vue.js vuejs2 vuex
add a comment |
up vote
0
down vote
favorite
I'm trying to access a state object property from a mutation in a Vuex Store but I can't find the right syntax :
Here is the state:
state:
events: [
day: 8
location: NY
,
day: 9:
location: NY
]
And here is the mutation :
SET_EVENT_LIST: (state, list) =>
if(list.day < 10)
list.day = '0'+list.day
state.events = list
,
I want to change the value of each event.day
under 10. What am I doing wrong?
javascript vue.js vuejs2 vuex
1
if thelist
is an array, solist.day
doesn't make sense. you should uselist.map
function.
– Madmadi
Nov 9 at 22:45
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I'm trying to access a state object property from a mutation in a Vuex Store but I can't find the right syntax :
Here is the state:
state:
events: [
day: 8
location: NY
,
day: 9:
location: NY
]
And here is the mutation :
SET_EVENT_LIST: (state, list) =>
if(list.day < 10)
list.day = '0'+list.day
state.events = list
,
I want to change the value of each event.day
under 10. What am I doing wrong?
javascript vue.js vuejs2 vuex
I'm trying to access a state object property from a mutation in a Vuex Store but I can't find the right syntax :
Here is the state:
state:
events: [
day: 8
location: NY
,
day: 9:
location: NY
]
And here is the mutation :
SET_EVENT_LIST: (state, list) =>
if(list.day < 10)
list.day = '0'+list.day
state.events = list
,
I want to change the value of each event.day
under 10. What am I doing wrong?
javascript vue.js vuejs2 vuex
javascript vue.js vuejs2 vuex
edited Nov 9 at 23:30
Boussadjra Brahim
3,6702627
3,6702627
asked Nov 9 at 22:40
blickblick
426
426
1
if thelist
is an array, solist.day
doesn't make sense. you should uselist.map
function.
– Madmadi
Nov 9 at 22:45
add a comment |
1
if thelist
is an array, solist.day
doesn't make sense. you should uselist.map
function.
– Madmadi
Nov 9 at 22:45
1
1
if the
list
is an array, so list.day
doesn't make sense. you should use list.map
function.– Madmadi
Nov 9 at 22:45
if the
list
is an array, so list.day
doesn't make sense. you should use list.map
function.– Madmadi
Nov 9 at 22:45
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
the right syntax should be like :
const store = new Vuex.Store(
state:
events: [
day: 8
location: "NY"
,
day: 9,
location: "NY"
]
,
mutations:
SET_EVENT_LIST (state, list)
state.events = list.map(l=>
if (l.day < 10)
l.day = '0' + l.day
return l;
else return l;
)
)
Notes
- the values of location key should be strings
Each method in
mutations
should have this syntax :mutations:
method_name(state,other_parameters)...
or
mutations:
method_name:(state,other_parameters)=>...
Map function example
let events = [
day: 7,
loc: "NY"
,
day: 8,
loc: "NY"
,
day: 18,
loc: "Paris"
];
let custom_events = events.map(l =>
if (l.day < 10)
l.day = '0' + l.day
return l;
else return l;
);
console.log(custom_events);
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
the right syntax should be like :
const store = new Vuex.Store(
state:
events: [
day: 8
location: "NY"
,
day: 9,
location: "NY"
]
,
mutations:
SET_EVENT_LIST (state, list)
state.events = list.map(l=>
if (l.day < 10)
l.day = '0' + l.day
return l;
else return l;
)
)
Notes
- the values of location key should be strings
Each method in
mutations
should have this syntax :mutations:
method_name(state,other_parameters)...
or
mutations:
method_name:(state,other_parameters)=>...
Map function example
let events = [
day: 7,
loc: "NY"
,
day: 8,
loc: "NY"
,
day: 18,
loc: "Paris"
];
let custom_events = events.map(l =>
if (l.day < 10)
l.day = '0' + l.day
return l;
else return l;
);
console.log(custom_events);
add a comment |
up vote
0
down vote
the right syntax should be like :
const store = new Vuex.Store(
state:
events: [
day: 8
location: "NY"
,
day: 9,
location: "NY"
]
,
mutations:
SET_EVENT_LIST (state, list)
state.events = list.map(l=>
if (l.day < 10)
l.day = '0' + l.day
return l;
else return l;
)
)
Notes
- the values of location key should be strings
Each method in
mutations
should have this syntax :mutations:
method_name(state,other_parameters)...
or
mutations:
method_name:(state,other_parameters)=>...
Map function example
let events = [
day: 7,
loc: "NY"
,
day: 8,
loc: "NY"
,
day: 18,
loc: "Paris"
];
let custom_events = events.map(l =>
if (l.day < 10)
l.day = '0' + l.day
return l;
else return l;
);
console.log(custom_events);
add a comment |
up vote
0
down vote
up vote
0
down vote
the right syntax should be like :
const store = new Vuex.Store(
state:
events: [
day: 8
location: "NY"
,
day: 9,
location: "NY"
]
,
mutations:
SET_EVENT_LIST (state, list)
state.events = list.map(l=>
if (l.day < 10)
l.day = '0' + l.day
return l;
else return l;
)
)
Notes
- the values of location key should be strings
Each method in
mutations
should have this syntax :mutations:
method_name(state,other_parameters)...
or
mutations:
method_name:(state,other_parameters)=>...
Map function example
let events = [
day: 7,
loc: "NY"
,
day: 8,
loc: "NY"
,
day: 18,
loc: "Paris"
];
let custom_events = events.map(l =>
if (l.day < 10)
l.day = '0' + l.day
return l;
else return l;
);
console.log(custom_events);
the right syntax should be like :
const store = new Vuex.Store(
state:
events: [
day: 8
location: "NY"
,
day: 9,
location: "NY"
]
,
mutations:
SET_EVENT_LIST (state, list)
state.events = list.map(l=>
if (l.day < 10)
l.day = '0' + l.day
return l;
else return l;
)
)
Notes
- the values of location key should be strings
Each method in
mutations
should have this syntax :mutations:
method_name(state,other_parameters)...
or
mutations:
method_name:(state,other_parameters)=>...
Map function example
let events = [
day: 7,
loc: "NY"
,
day: 8,
loc: "NY"
,
day: 18,
loc: "Paris"
];
let custom_events = events.map(l =>
if (l.day < 10)
l.day = '0' + l.day
return l;
else return l;
);
console.log(custom_events);
let events = [
day: 7,
loc: "NY"
,
day: 8,
loc: "NY"
,
day: 18,
loc: "Paris"
];
let custom_events = events.map(l =>
if (l.day < 10)
l.day = '0' + l.day
return l;
else return l;
);
console.log(custom_events);
let events = [
day: 7,
loc: "NY"
,
day: 8,
loc: "NY"
,
day: 18,
loc: "Paris"
];
let custom_events = events.map(l =>
if (l.day < 10)
l.day = '0' + l.day
return l;
else return l;
);
console.log(custom_events);
edited Nov 9 at 23:26
answered Nov 9 at 22:54
Boussadjra Brahim
3,6702627
3,6702627
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53234180%2faccessing-to-state-object-property-from-mutations%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
if the
list
is an array, solist.day
doesn't make sense. you should uselist.map
function.– Madmadi
Nov 9 at 22:45