Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

262
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda