从 vuex store 模块访问全局 vue 变量
Access global vue variable from vuex store module
我希望有人能在这里为我指明正确的方向。
在我的 Vue.js 应用程序中,我在 main.ts
中定义了一个全局变量 $test
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');
如何从 Vuex 存储模块访问此变量?我试过 this.$test
和其他组合,但没有成功。
这来自 vuex 存储模块(在本例中已缩短)。此模块作为单独的模块导入到我的store.ts。
export default {
state: {
.....
},
mutations: {
......
},
actions: {
testMyVar(context: any) {
console.log(this.$test); //What am I doing wrong here???
}
},
getters: {
....
}
}
编辑:基本上我想做的是模拟一个库并从我本地开发站的 index.html 启动它。然后使启动的 class 在我的商店模块中可用。
在生产中,class 已经启动,只需要从我的 vuex 存储模块访问该变量。
谢谢
import Vue from 'vue'
export default {
state: {
.....
},
mutations: {
......
},
actions: {
testMyVar(context: any) {
console.log(Vue.prototype.$test); //just import vue in store
}
},
getters: {
....
}
}
我希望有人能在这里为我指明正确的方向。 在我的 Vue.js 应用程序中,我在 main.ts
中定义了一个全局变量 $testimport 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');
如何从 Vuex 存储模块访问此变量?我试过 this.$test
和其他组合,但没有成功。
这来自 vuex 存储模块(在本例中已缩短)。此模块作为单独的模块导入到我的store.ts。
export default {
state: {
.....
},
mutations: {
......
},
actions: {
testMyVar(context: any) {
console.log(this.$test); //What am I doing wrong here???
}
},
getters: {
....
}
}
编辑:基本上我想做的是模拟一个库并从我本地开发站的 index.html 启动它。然后使启动的 class 在我的商店模块中可用。
在生产中,class 已经启动,只需要从我的 vuex 存储模块访问该变量。
谢谢
import Vue from 'vue'
export default {
state: {
.....
},
mutations: {
......
},
actions: {
testMyVar(context: any) {
console.log(Vue.prototype.$test); //just import vue in store
}
},
getters: {
....
}
}