I am working on a vue
application and I have a query.
How can I access the store from javascript/typescript modules files using import/export?
For example, if I create an auth-module that exports state, actions, mutations:
export const auth = {
namespaced: true,
state,
actions,
mutations,
getters,
};
In my app, I import the module to my store like this:
Vue.use(Vuex);
export const store = new Vuex.Store({
modules: {
auth,
}
});
Now, I want to create an interceptor (inside my auth-module) for my http calls to add the token from the store.
Vue.http.interceptors.push((request: any) => {
// ---> How do I access store.state.token???
// request.headers.set('Authorization', 'Bearer TOKEN');
});
But how can I access the state of the store without depending on my app?
import {store} from './store'
but is it possible to import the store instance from the vue
or vuex
module directly.