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

200
Vistas
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 Respuestas
Responde la pregunta

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 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