Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

197
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!