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...
Edit this page on GitHub Updated at Fri, Oct 22, 2021