diff --git a/examples/axios/README.md b/examples/axios/README.md new file mode 100644 index 0000000000..a2f03635fc --- /dev/null +++ b/examples/axios/README.md @@ -0,0 +1,32 @@ +# Axios Proxy Example + +## Install + +```bash +$ yarn add @nuxtjs/axios @nuxtjs/proxy +``` + +## Nuxt.config.js + +```json +{ + modules: [ + '@nuxtjs/axios', + '@nuxtjs/proxy' + ], + proxy: [ + ['/api/dog', { target: 'https://dog.ceo/', pathRewrite: { '^/api/dog': '/api/breeds/image/random' } }] + ] +} +``` + +### Use Axios + +```js +async asyncData({ app }) { + const ip = await app.$axios.$get('http://icanhazip.com') + return { ip } +} +``` + +More detail, please refer [axios-module](https://github.com/nuxt-community/axios-module). diff --git a/examples/axios/nuxt.config.js b/examples/axios/nuxt.config.js new file mode 100644 index 0000000000..350033d068 --- /dev/null +++ b/examples/axios/nuxt.config.js @@ -0,0 +1,9 @@ +module.exports = { + modules: [ + '@nuxtjs/axios', + '@nuxtjs/proxy' + ], + proxy: [ + ['/api/dog', { target: 'https://dog.ceo/', pathRewrite: { '^/api/dog': '/api/breeds/image/random' } }] + ] +} diff --git a/examples/axios/package.json b/examples/axios/package.json new file mode 100644 index 0000000000..296b93f26d --- /dev/null +++ b/examples/axios/package.json @@ -0,0 +1,14 @@ +{ + "name": "nuxt-proxy", + "version": "1.0.0", + "dependencies": { + "@nuxtjs/axios": "^4.4.0", + "@nuxtjs/proxy": "^1.1.2", + "nuxt": "latest" + }, + "scripts": { + "dev": "nuxt", + "build": "nuxt build", + "start": "nuxt start" + } +} diff --git a/examples/axios/pages/index.vue b/examples/axios/pages/index.vue new file mode 100644 index 0000000000..68df7c6dce --- /dev/null +++ b/examples/axios/pages/index.vue @@ -0,0 +1,17 @@ + + +