The @nuxtjs/axios module is well integrated with the @nuxtjs/proxy module and is very useful in many cases. Preventing the CORS problem is one of the benefits of using these two modules together. You learned how to install and use them in Chapter 6, Writing Plugins and Modules. Let's recap:
- Install the @nuxtjs/axios and @nuxtjs/proxy modules via npm:
$ npm install @nuxtjs/axios
$ npm install @nuxtjs/proxy
- Register @nuxtjs/axios in the modules option in the Nuxt config file, as follows:
// nuxt.config.js
module.exports = {
modules: [
'@nuxtjs/axios'
],
axios: {
proxy: true
},
proxy: {
'/api/': { target: 'http://0.0.0.0:8181',
pathRewrite: {'^/api/': ''} }
}
}
Note that it is not required to register the @nuxtjs/proxy module when you are using it with @nuxtjs/axios, as long as it is installed and in the dependencies field in package.json.
In the preceding configuration, we use /api/ as the...