mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-14 01:53:55 +00:00
917 B
917 B
Nuxt with Axios Proxy Example
Using proxy-module and Axios module
proxy-module is the one-liner node.js http-proxy middleware solution for Nuxt using http-proxy-middleware
Axios-module is a secure and easy Axios integration with Nuxt.
Install
$ yarn add @nuxtjs/axios @nuxtjs/proxy
Nuxt.config.js
{
modules: [
'@nuxtjs/axios',
'@nuxtjs/proxy'
],
proxy: [
['/api/dog', { target: 'https://dog.ceo/', pathRewrite: { '^/api/dog': '/api/breeds/image/random' } }]
]
}
Use Axios
async asyncData({ app }) {
const ip = await app.$axios.$get('http://icanhazip.com')
return { ip }
}
More detail, please refer axios-module.