Quantcast
Channel: Active questions tagged javascript - Stack Overflow
Viewing all articles
Browse latest Browse all 140734

How to set an header with Axios module and vuejs in nuxt

$
0
0

I'm trying to define an "Accept-Language" header for my SPA in vue.js (with nuxt).

Here's what I tried but it doesn't work. I specify that I use the axios module for nuxt.

I created a plugin as explained in the documentation. I included the plugin in nuxt.config.js.

I tried to use setHeader as explained here, but it doesn't work.

export default function ({ store, $axios, redirect }) {
  $axios.setBaseURL(process.env.BASE_URL);

  if (process.server) {
    return
  }

  $axios.onRequest(config => {
    const baseUrl = $axios.defaults.baseURL;

    const locale = store.getters['lang/locale'];

    if (locale) {
      $axios.setHeader('Accept-Language', locale)
    }
  });
}

But this code doesn't work. However, when I make console.log, I see them so it is taken into account.


Viewing all articles
Browse latest Browse all 140734

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>