From 8f14fdfd824b496d1d87c3886e5264860c1dc6d1 Mon Sep 17 00:00:00 2001 From: Clark Du Date: Sun, 29 Oct 2017 17:08:42 +0800 Subject: [PATCH] feat: add axios and proxy example --- examples/axios/README.md | 32 ++++++++++++++++++++++++++++++++ examples/axios/nuxt.config.js | 9 +++++++++ examples/axios/package.json | 14 ++++++++++++++ examples/axios/pages/index.vue | 17 +++++++++++++++++ 4 files changed, 72 insertions(+) create mode 100644 examples/axios/README.md create mode 100644 examples/axios/nuxt.config.js create mode 100644 examples/axios/package.json create mode 100644 examples/axios/pages/index.vue 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 @@ + + +