Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

272
Vistas
How to combine 2 vuex stores into a single store

Hi i have a requirement of combining 2 vuex store into a single store (both stores are of different projects)

import storeA from '/path';

import storeB from '/path';

now combined both store

const combinedStore = //combine logic as i don't know this logic

I searched a lot on stackoverflow to combine 2 vuex store but i did not find any solution so posted.

here is how my vuex store will look like in both the stores

Store 1:

   // storeA.js
    
    const store = {
        state(){return {}},
        actions: {async getData(){...}},
        mutations: {},
        getters: {}, 
        modules:{ 
           Login
        }
    }

Store 2:

   // storeB.js
    
    const store = {
        state(){return {}},
        actions: {async getUsers(){...}},
        mutations: {},
        getters: {}, 
        modules:{ 
           workflow
        }
    }

Here is how i tried:

import StoreA from 'storeA.js';
import StoreB from 'storeB.js';

const newStoreData = Object.assign({},StoreA,StoreB)

const newStore = new Vuex.Store({
    ...newStoreData
});

Now only 1 store will work other will throw error like

reading first_name name of undefined (i,e state.[module].first_name)

Problem can be re-produced here: https://codesandbox.io/s/vuex-playground-forked-1h344?file=/src/main.js

Original working fork: https://codesandbox.io/s/k012qvkmnv?file=/src/main.js

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

Vue 3+

lover versions probably has this method too but im not sure.

import StoreA from 'storeA.js';
import StoreB from 'storeB.js';

const newStore = new Vuex.Store(storeA);

newStore.registerModule('', storeB)

I just modified store2.js and main.js files

link to solved problem: https://codesandbox.io/s/vuex-playground-forked-6pg4w?file=/src/main.js

Here is a documentation about it: https://vuex.vuejs.org/guide/modules.html#dynamic-module-registration

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda