Vuex Modules Creating Nested Object
up vote
0
down vote
favorite
I have been trying to separate my store.js file into multiple store modules. I have it working (somewhat), but it also created kind of a big issue.
In my initial one single file store, let's suppose this is my state object:
state: user: ''
And the output in the Vuex developer tools shows the user object as it should:
User: name: "John", age: 33
But after splitting the the store into modules the user object in the Vuex developer tools is as follows:
User: User: name: "John", age: 33
So it creates a new object using the name I give it in the modules object and import in the main store.js file, which then contains the "true" user object.
Is there any way to have it not create a new object and keep it the same as if the entire store lived inside the store.js file?
-Sergio
EDIT:
Here is the structure of my files:
store
store.js
modules
user.js
The code in the modules/user.js:
const state = User: ''
const mutations = ...
const actions = ...
export default state, mutations, actions
The code in my store.js
import User from './modules/user';
Vue.use(Vuex);
export default new Vuex.Store(
modules:
User
);
Prior to externalizing the store I would get in Vuex dev tools:User: name: "John", age: 33
After externalizing the store I get:User: User: name: "John", age: 33
It's nesting User from the modules/user file inside the User in the store.js file. I want to avoid that (if its possible) so that I don't have to change everything in my components/template files.
vue.js store vuex
|
show 1 more comment
up vote
0
down vote
favorite
I have been trying to separate my store.js file into multiple store modules. I have it working (somewhat), but it also created kind of a big issue.
In my initial one single file store, let's suppose this is my state object:
state: user: ''
And the output in the Vuex developer tools shows the user object as it should:
User: name: "John", age: 33
But after splitting the the store into modules the user object in the Vuex developer tools is as follows:
User: User: name: "John", age: 33
So it creates a new object using the name I give it in the modules object and import in the main store.js file, which then contains the "true" user object.
Is there any way to have it not create a new object and keep it the same as if the entire store lived inside the store.js file?
-Sergio
EDIT:
Here is the structure of my files:
store
store.js
modules
user.js
The code in the modules/user.js:
const state = User: ''
const mutations = ...
const actions = ...
export default state, mutations, actions
The code in my store.js
import User from './modules/user';
Vue.use(Vuex);
export default new Vuex.Store(
modules:
User
);
Prior to externalizing the store I would get in Vuex dev tools:User: name: "John", age: 33
After externalizing the store I get:User: User: name: "John", age: 33
It's nesting User from the modules/user file inside the User in the store.js file. I want to avoid that (if its possible) so that I don't have to change everything in my components/template files.
vue.js store vuex
But how are you doing this assignment?
– Hamilton Gabriel
13 hours ago
Hi Hamilton, I don't understand your question...can you please rephrase.
– Sergio
13 hours ago
At what point in time do you do this assignment? And how is this assignment being done? Are you calling this assignment more than once?
– Hamilton Gabriel
12 hours ago
I have updated my initial question, hope it clarifies more.
– Sergio
12 hours ago
Are you assigning the user again in vuex, or are you doing this yourself?
– Hamilton Gabriel
12 hours ago
|
show 1 more comment
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have been trying to separate my store.js file into multiple store modules. I have it working (somewhat), but it also created kind of a big issue.
In my initial one single file store, let's suppose this is my state object:
state: user: ''
And the output in the Vuex developer tools shows the user object as it should:
User: name: "John", age: 33
But after splitting the the store into modules the user object in the Vuex developer tools is as follows:
User: User: name: "John", age: 33
So it creates a new object using the name I give it in the modules object and import in the main store.js file, which then contains the "true" user object.
Is there any way to have it not create a new object and keep it the same as if the entire store lived inside the store.js file?
-Sergio
EDIT:
Here is the structure of my files:
store
store.js
modules
user.js
The code in the modules/user.js:
const state = User: ''
const mutations = ...
const actions = ...
export default state, mutations, actions
The code in my store.js
import User from './modules/user';
Vue.use(Vuex);
export default new Vuex.Store(
modules:
User
);
Prior to externalizing the store I would get in Vuex dev tools:User: name: "John", age: 33
After externalizing the store I get:User: User: name: "John", age: 33
It's nesting User from the modules/user file inside the User in the store.js file. I want to avoid that (if its possible) so that I don't have to change everything in my components/template files.
vue.js store vuex
I have been trying to separate my store.js file into multiple store modules. I have it working (somewhat), but it also created kind of a big issue.
In my initial one single file store, let's suppose this is my state object:
state: user: ''
And the output in the Vuex developer tools shows the user object as it should:
User: name: "John", age: 33
But after splitting the the store into modules the user object in the Vuex developer tools is as follows:
User: User: name: "John", age: 33
So it creates a new object using the name I give it in the modules object and import in the main store.js file, which then contains the "true" user object.
Is there any way to have it not create a new object and keep it the same as if the entire store lived inside the store.js file?
-Sergio
EDIT:
Here is the structure of my files:
store
store.js
modules
user.js
The code in the modules/user.js:
const state = User: ''
const mutations = ...
const actions = ...
export default state, mutations, actions
The code in my store.js
import User from './modules/user';
Vue.use(Vuex);
export default new Vuex.Store(
modules:
User
);
Prior to externalizing the store I would get in Vuex dev tools:User: name: "John", age: 33
After externalizing the store I get:User: User: name: "John", age: 33
It's nesting User from the modules/user file inside the User in the store.js file. I want to avoid that (if its possible) so that I don't have to change everything in my components/template files.
vue.js store vuex
vue.js store vuex
edited 12 hours ago
asked 13 hours ago
Sergio
356112
356112
But how are you doing this assignment?
– Hamilton Gabriel
13 hours ago
Hi Hamilton, I don't understand your question...can you please rephrase.
– Sergio
13 hours ago
At what point in time do you do this assignment? And how is this assignment being done? Are you calling this assignment more than once?
– Hamilton Gabriel
12 hours ago
I have updated my initial question, hope it clarifies more.
– Sergio
12 hours ago
Are you assigning the user again in vuex, or are you doing this yourself?
– Hamilton Gabriel
12 hours ago
|
show 1 more comment
But how are you doing this assignment?
– Hamilton Gabriel
13 hours ago
Hi Hamilton, I don't understand your question...can you please rephrase.
– Sergio
13 hours ago
At what point in time do you do this assignment? And how is this assignment being done? Are you calling this assignment more than once?
– Hamilton Gabriel
12 hours ago
I have updated my initial question, hope it clarifies more.
– Sergio
12 hours ago
Are you assigning the user again in vuex, or are you doing this yourself?
– Hamilton Gabriel
12 hours ago
But how are you doing this assignment?
– Hamilton Gabriel
13 hours ago
But how are you doing this assignment?
– Hamilton Gabriel
13 hours ago
Hi Hamilton, I don't understand your question...can you please rephrase.
– Sergio
13 hours ago
Hi Hamilton, I don't understand your question...can you please rephrase.
– Sergio
13 hours ago
At what point in time do you do this assignment? And how is this assignment being done? Are you calling this assignment more than once?
– Hamilton Gabriel
12 hours ago
At what point in time do you do this assignment? And how is this assignment being done? Are you calling this assignment more than once?
– Hamilton Gabriel
12 hours ago
I have updated my initial question, hope it clarifies more.
– Sergio
12 hours ago
I have updated my initial question, hope it clarifies more.
– Sergio
12 hours ago
Are you assigning the user again in vuex, or are you doing this yourself?
– Hamilton Gabriel
12 hours ago
Are you assigning the user again in vuex, or are you doing this yourself?
– Hamilton Gabriel
12 hours ago
|
show 1 more comment
1 Answer
1
active
oldest
votes
up vote
0
down vote
Given your initial store state:
state: user: ''
And an object with the following shape representing a user:
name: "John", age: 33
You can write a mutation as:
SET_USER: (state, user) =>
Object.assign(state, user )
Commit the user:
this.$store.commit('SET_USER', user)
This is assuming no module namespaces of course.
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
Given your initial store state:
state: user: ''
And an object with the following shape representing a user:
name: "John", age: 33
You can write a mutation as:
SET_USER: (state, user) =>
Object.assign(state, user )
Commit the user:
this.$store.commit('SET_USER', user)
This is assuming no module namespaces of course.
add a comment |
up vote
0
down vote
Given your initial store state:
state: user: ''
And an object with the following shape representing a user:
name: "John", age: 33
You can write a mutation as:
SET_USER: (state, user) =>
Object.assign(state, user )
Commit the user:
this.$store.commit('SET_USER', user)
This is assuming no module namespaces of course.
add a comment |
up vote
0
down vote
up vote
0
down vote
Given your initial store state:
state: user: ''
And an object with the following shape representing a user:
name: "John", age: 33
You can write a mutation as:
SET_USER: (state, user) =>
Object.assign(state, user )
Commit the user:
this.$store.commit('SET_USER', user)
This is assuming no module namespaces of course.
Given your initial store state:
state: user: ''
And an object with the following shape representing a user:
name: "John", age: 33
You can write a mutation as:
SET_USER: (state, user) =>
Object.assign(state, user )
Commit the user:
this.$store.commit('SET_USER', user)
This is assuming no module namespaces of course.
answered 12 hours ago
DigitalDrifter
5,7142422
5,7142422
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
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53236866%2fvuex-modules-creating-nested-object%23new-answer', 'question_page');
);
Post as a guest
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
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
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
But how are you doing this assignment?
– Hamilton Gabriel
13 hours ago
Hi Hamilton, I don't understand your question...can you please rephrase.
– Sergio
13 hours ago
At what point in time do you do this assignment? And how is this assignment being done? Are you calling this assignment more than once?
– Hamilton Gabriel
12 hours ago
I have updated my initial question, hope it clarifies more.
– Sergio
12 hours ago
Are you assigning the user again in vuex, or are you doing this yourself?
– Hamilton Gabriel
12 hours ago