Nuxt/examples/axios
2017-10-31 21:43:55 +08:00
..
pages refactor: add examples to lint 2017-10-31 21:43:55 +08:00
nuxt.config.js feat: add axios and proxy example 2017-10-29 17:08:42 +08:00
package.json feat: add axios and proxy example 2017-10-29 17:08:42 +08:00
README.md feat: add axios and proxy example 2017-10-29 17:08:42 +08:00

Axios Proxy Example

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.