Nuxt.js: How can i access to store from a plugin?

Created on 28 Jul 2017  路  2Comments  路  Source: nuxt/nuxt.js

I'm using axios. It needs the Authorization header with bearer token on every request. The token is in the store.

import axios from 'axios'

let instance = axios.create({
  baseURL: 'http://api.docstore.dev'
})

instance.interceptors.request.use(config => {
  // How can i access this store instance below
  config.headers['Authorization'] = 'Bearer ' + store.state.accessToken

  return config
})

export default instance

Thank you!

Most helpful comment

All 2 comments

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

nassimbenkirane picture nassimbenkirane  路  3Comments

pehbehbeh picture pehbehbeh  路  3Comments

mattdharmon picture mattdharmon  路  3Comments

o-alexandrov picture o-alexandrov  路  3Comments

bimohxh picture bimohxh  路  3Comments