You are browsing Nuxt 2 docs. Go to Nuxt 3 docs, or learn more about Nuxt 2 Long Term Support.

Axios usage

In the first example we show how to use the env property in our nuxt.config.js file to add the URL of our API so that we can then easily make calls to it without having to use the URL on our page


In this example:

nuxt.config.js contains :

  • the publicRuntimeConfig property to add the URL of our API.
  • the modules property to register our @nuxtjs/axios module.

pages/index.vue - uses $axios to fetch our data and $config to retrieve our API URL.

Loading Sandbox...