bamgae
bamgae

Reputation: 301

nuxtjs/axios What is the way to initialize version 4.4.0? (nuxt.js)

I would like to use the nuxtjs/axios module.

At first, I install the module with npm

npm install nuxtjs/axios

Then I set the options in the nuxt.config.js file.

modules: [
  ['@ nuxtjs/axios', {
    baseURL: 'http://localhost: 4000',
    browserBaseURL: '/api',
  }],
]

When I start the app with

npm run dev

I expect the below output:

enter image description here

In nuxtjs/axios version 2.1.0, it is built as follows.

enter image description here

[AXIOS] Base URL: http: // localhost: 3000 /, Browser: /

Why can not I see the above message?

I think it might be because of a problem with asyncData () {}.

Also browserBaseURL: '/ api' does not work.

Upvotes: 3

Views: 1984

Answers (1)

Schwesi
Schwesi

Reputation: 4904

You should seperate the axios module inclusion and the options.

modules: [
  '@nuxtjs/axios'
],
axios: {
  baseURL: 'http://localhost: 4000',
  browserBaseURL: '/api'
}

This might just be a typo but the module should be installed using the npm i -S @nuxtjs/axios command (with the @).

Also by default the browserBaseURL is set to api, so you do not have to set it manually.

Please refer to the documentation for more information: https://github.com/nuxt-community/axios-module#browserbaseurl

Upvotes: 1

Related Questions