I am working with Vuex and I am quite new to it. I am wanting to commit data to the store and replace replace the state with content of the payload.
My store is built using modules and the module in question is the user module,
Currently I am doing something like in my mutation,
setUser(state, payload) {
state.user = {...payload.user}
}
This makes my state looks like this after a run a commit
user: {
user: {
nickname: 'Bob',
host: true,
emoji: 'Smile',
passcode: 12345678,
room_id: 123
}
}
Ideally I don't want to have a user object in a user object, I either want each attribute of user to part of the state like,
state : {
nickname: 'Bob',
host: true,
emoji: 'Smile',
passcode: 12345678,
room_id: 123
}
or it could look like this,
state : {
user: {
nickname: 'Bob',
host: true,
emoji: 'Smile',
passcode: 12345678,
room_id: 123
}
}
I don't understand why I am getting state.user.user
?
here is the user module of my state,
export default {
state: {
user: {}
},
mutations: {
setUser(state, payload) {
state.user = {...payload.user}
}
},
actions: {
},
getters: {
}
};
I have also tried the above with just state:{}
console.log(payload)
in thesetUser(state, payload)
method – isebarn