DEV Community

Discussion on: TIP - Import Vuejs Modules at once.

Collapse
 
morgothx profile image
Camilo Castro

Hi, thank you for the post.

I have a question if you can help me.

I have the following folder structure in my project

project
|
-store
|
|-constants.js
|-modules
|
|-someModule
|-otherModule
|-index.js (just as in your post)

This is a sample from my constants file

//Actions
export const USER_SET = 'user/SET'
export const USER_GET_ROLES = 'user/GET_ROLES'
//Mutations
export const USER_SET_BY_KEY = 'user/SET_BY_KEY'
export const USER_SET_ROLES = 'user/SET_ROLES'

And in my modules I use the constant as name for the actions, mutations, getters, like in this sample

const actions =
{
[constants.USER_SET]: ({commit}, user) =>
{
let response = {'data': user, 'key': 'user' }
commit(constants.USER_SET_BY_KEY, response)
},
}

The idea is that when I use in components, i use the constants file name too, this way I can change the name in one place

Like in this

...mapActions({
getRoles: constants.USER_GET_ROLES,

The thing is, even when the module are dinamically loaded by the index in the modules folder, Vuex doesn't recognize the actions, mutations, getters

I print the modules object in the index and i see that it has this properties empty

{
"customer": {
"state": {
"customers": null,
"contacts": null
},
"actions": {},
"mutations": {},
"getters": {}
},
.
.
.
.

}

If I go back to import every module manually and put then in the vuex individually, then vuex recognize the actions, mutations, getters

So thank you in advance if can you please point me in the right direction

p.s Sorry for my bad english, it's not my native language

Collapse
 
morgothx profile image
Camilo Castro

Nevermind, It was a problem with the way I was telling vuex to use modules but thank you anyway

Collapse
 
simo_benhida profile image
mohamed benhida

Glad you figured it out !