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

120
Visualizações
Is it possible to inject a vuex store depending on the route?

The app I'm working on has multiple stores with modules inside. I would like to inject the store globally depending on the path route. Is this possible to do?

import VueRouter from 'vue-router';
import Vuex from 'vuex';
Vue.use(VueRouter);
Vue.use(Vuex);

const router = new VueRouter({
routes: [
{ path:"/", component:Homepage},
{ path:"/Site", component:Sitepage}
], mode: 'history');

 new Vue({router, store }).$mount('#app');

I have each store in a list, e.g. stores = [HomepageStore, SitepageStore];

I tried combining the individual stores and making a whole store from it like this:

const store = new Vuex.Store({
  modules: {
    HomepageStore, SitepageStore
  }
});

This shows a blank page with no errors, even though it shows the store data and the routes, it doesn't show any elements on the page. It doesn't help it already has modules inside. There are about 50 store files so I do not want to alter each one in case. Any help would be much appreciated.

Just to update I am using vue 2.6.12 and vue-router 3.1.6

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

https://vuex.vuejs.org/guide/modules.html

I think your formatting isn't correct please try

const store = new Vuex.Store({
  modules: {
    homepageStore: HomepageStore, 
    sitepageStore: SitepageStore
  }
});

Accessing your stores can then be done with

this.$store.state.homepageStore....
this.$store.state.sitepageStore....

Or you could create a global variable that has multiple stores

window._globalStore = stores;
about 4 years ago · Juan Pablo Isaza 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