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

199
Visualizações
Access global vue variable from vuex store module

I hope someone can point me in the right direction here. In my Vue.js application, I have defined a global variable $test in my main.ts

import Vue from 'vue'
import App from './App.vue'
import { store } from '../src/store/store';


Vue.config.productionTip = false

Vue.prototype.$store = store;

Vue.prototype.$test = 'Testing';

new Vue({
    store,
    render: h => h(App)
}).$mount('#app');

How do I access this variable from a Vuex store module? I've tried this.$test and other combinations with no luck.

This is from the vuex store module (shortened for this example). This module is imported to my store.ts as a separate module.

export default {
    state: {
        .....
    },
    mutations: {
        ......
    },
    actions: {
        testMyVar(context: any) {
            console.log(this.$test); //What am I doing wrong here???
        }
    },
    getters: {
        ....
    }
}

Edit: basically what I want to do is to mock a library and initiate it from my index.html on my local dev station. Then make the initiated class available from my store modules.

In production the class is already initiated and the variable just needs to be accessible from my vuex store modules.

Thanks

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

0

import Vue from 'vue'

export default {
state: {
    .....
},
mutations: {
    ......
},
actions: {
    testMyVar(context: any) {
        console.log(Vue.prototype.$test); //just import vue in store
    }
},
getters: {
    ....
}

}

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