I use Axios in my store actions and wish to set an Axios header based on some state(to change the request header for accepted languages). When trying to access the store outside the export, I get an error "cannot find property state of undefined". My store/index.js file:
import Vue from "vue";
import Vuex, { Store } from "vuex";
import Axios from "axios";
Vue.use(Vuex);
Axios.defaults.headers['Accept-Language'] = store.state.Lang
const store = new Vuex.Store({
state: {
Lang: "en",
ApiConf: [],
Token: null,
Session: null,
}
...
}
export default store
How would you access the store and state in the same file where the store is defined? Or how would you go about implementing this state-dependent Axios header without going into the store and defining for every action?