title: Can't access Vuex storage mutation inside Axios interceptor
body: <p><strong>EDIT:</strong> this question was very chaotic so I basically rewrite it with same code example and same scenerio.</p>
  <hr>
  <p>When 401 error is send in response from server I'm trying to <code>.commit</code> from interceptor to my vuex storage:</p>
  <pre><code>import axios from 'axios';
  import { store } from '../store/store';
  
  export default function execute() {
      axios.interceptors.request.use(function(config) {
          const token = store.state.token;
          if(token) {
              config.headers.Authorization = `Bearer ${token}`;
              //console.log(config);
              return config;
          } else {
              return config;
          }
      }, function(err) {
          return Promise.reject(err);
      });
      axios.interceptors.response.use((response) =&gt; {
          return response;
      }, (err) =&gt; {
          console.log(err.response.status);
          if(err.response.status === 401) {
              this.$store.commit('logout');
          }
          console.log('err'); // this doesnt even console log
          return Promise.reject(err);
      });
  }
  </code></pre>
  <p>But it's throwing error</p>
  <blockquote>
  <p>TypeError: Cannot read property '$store' of undefined</p>
  <p>at eval (httpInterceptor.js?bdcd:22)</p>
  </blockquote>
  <p>I don't know why I think that I import it correctly.</p>
  <p>I use arrow functions, I also tried without arrow functions but it cause same error as above.</p>
  <p>I execute my interceptor in main.js by importing it and calling (<code>import interceptor from './helpers/httpInterceptor.js'; interceptor();</code>)</p>
  <p>My vuex storage file is:</p>
  <pre><code>import Vue from 'vue';
  import Vuex from 'vuex';
  import createPersistedState from 'vuex-persistedstate'
  
  Vue.use(Vuex);
  
  export const store = new Vuex.Store({
      state: {
          logged: false,
          token: ''
      },
      mutations: {
          login: (state, response) =&gt; {
              if(response) {
                  state.logged = true;
                  state.token = response;
                  console.log('state updated');
                  console.log('state.logged flag is: '+state.logged);
                  console.log('state.token: '+state.token);
              }
          },
          logout: (state) =&gt; {
              state.logged = false;
              state.token = '';
          }
      },
      plugins: [
          createPersistedState()
      ]
  });
  </code></pre>
  <p>and I'm assigning it to Vue instance</p>
  <pre><code>new Vue({
      el: '#app',
      router,
      store,
      template: '&lt;app/&gt;',
      components: { app }
  });
  </code></pre>
  <p>Why I can't use my mutation inside this interceptor, what is causing issue and how to fix it?</p>