Nuxt/examples/axios
2018-02-05 17:49:08 +08:00
..
pages refactor: add examples to lint 2017-10-31 21:43:55 +08:00
nuxt.config.js example: upgrade axios-module to 5.x 2018-02-05 17:49:08 +08:00
package.json example: upgrade axios-module to 5.x 2018-02-05 17:49:08 +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.