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
import Vue from 'vue'
export default {
state: {
.....
},
mutations: {
......
},
actions: {
testMyVar(context: any) {
console.log(Vue.prototype.$test); //just import vue in store
}
},
getters: {
....
}
}