I declare a global variable in the main.js
of the Vue.js project.
Vue.prototype.$API = "myapihere"
And I want to use this from everywhere.
and it's work properly by using this.$API
.
But in Vuex it does not work.
console.log(this.$API);
Here this.$API
is undefined.
How I use my $API
in Vuex.
Vue 2 and Vuex 3 answer
In the store you can access the vue instance by accessing this._vm
const store = new Vuex.Store({
mutations: {
test(state) {
console.log(this._vm);
}
}
});