title: Get $store data in ~/plugins/axios
body: <p>I'm new with VueJs, I'm finding best way to get $store data in ~/plugins/axios in VueJS in order to use it for APIs. But some errors occur. Hope your helps</p>
  
  <p><strong>~/plugins/axios.js</strong></p>
  
  <pre><code>import axios from 'axios'
  import store from '~/store'
  
  var api = axios.create({
    baseURL: 'http://localhost:8000/api/v1/',
    headers: {'Authorization': 'JWT ' + store.state.token}
  })
  
  export default api
  </code></pre>
  
  <p><strong>Errors:</strong></p>
  
  <p><code>Issues: Can't tranmit store in to axios.create, so store is not defined</code></p>
  
  <p><strong>My ~/Store.JS:</strong></p>
  
  <pre><code>const AuthenticationStore = () =&gt; {
    return new Vuex.Store({
      state: {
        token: null
      },
      mutations: {
        SET_TOKEN: function (state, token) {
          state.token = token
          instance.defaults.headers = { Authorization: 'Bearer ' + token }
        }
      },
      actions: {
        ....
      }
    })
  }
  
  const createStore = () =&gt; {
    return AuthenticationStore
  }
  export { AuthenticationStore }
  
  export default createStore
  </code></pre>
  
  <p>Error:
  <code>Cannot read property 'token' of undefined</code> in <code>'headers': {'Authorization': 'JWT ' + store.state.token}</code></p>