Nuxt/examples/axios
2018-03-19 10:41:46 +08:00
..
pages refactor: add examples to lint 2017-10-31 21:43:55 +08:00
nuxt.config.js feat: rewrite core to esm 2018-03-16 19:42:06 +03:30
package.json refactor: rename examples 2018-03-19 10:41:46 +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.