@nuxtjs/axios
Advanced tools
Comparing version 2.3.0 to 3.0.0
@@ -6,2 +6,18 @@ # Change Log | ||
<a name="3.0.0"></a> | ||
# [3.0.0](https://github.com/nuxt/modules/compare/@nuxtjs/axios@2.3.0...@nuxtjs/axios@3.0.0) (2017-07-25) | ||
### Code Refactoring | ||
* **axios:** remove $ shortcut mixins ([1ab2bd6](https://github.com/nuxt/modules/commit/1ab2bd6)) | ||
### BREAKING CHANGES | ||
* **axios:** You have to explicitly use `this.$axios.[method]` instead of `this.$[method]` | ||
<a name="2.3.0"></a> | ||
@@ -8,0 +24,0 @@ # [2.3.0](https://github.com/nuxt/modules/compare/@nuxtjs/axios@2.2.4...@nuxtjs/axios@2.3.0) (2017-07-24) |
{ | ||
"name": "@nuxtjs/axios", | ||
"version": "2.3.0", | ||
"version": "3.0.0", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -18,32 +18,2 @@ import Axios from 'axios' | ||
} | ||
// Vue Component Mixins | ||
Vue.mixin({ | ||
methods: { | ||
// opts | ||
$request (opts) { | ||
return this.$axios.request(opts); | ||
}, | ||
// url, opts | ||
$get (url, opts) { | ||
return this.$axios.get(url, opts); | ||
}, | ||
$delete (url, opts) { | ||
return this.$axios.delete(url, opts); | ||
}, | ||
$head (url, opts) { | ||
return this.$axios.head(url, opts); | ||
}, | ||
// url, data, opts | ||
$post (url, data, opts) { | ||
return this.$axios.post(url, data, opts); | ||
}, | ||
$put (url, data, opts) { | ||
return this.$axios.put(url, data, opts); | ||
}, | ||
$patch (url, data, opts) { | ||
return this.$axios.patch(url, data, opts); | ||
} | ||
} | ||
}) | ||
} | ||
@@ -128,3 +98,3 @@ } | ||
<% if(options.proxyHeaders) { %> | ||
// Default headers | ||
// Default headers | ||
const defaultHeaders = (req && req.headers) ? Object.assign({}, req.headers) : {} | ||
@@ -131,0 +101,0 @@ delete defaultHeaders.host |
@@ -5,6 +5,5 @@ # Axios | ||
> Use [axios](https://github.com/mzabriskie/axios) with deep Nuxt integration and no pain! | ||
> Use [axios](https://github.com/mzabriskie/axios) with deep Nuxt integration and no pain! | ||
- Automatically set base URL for client & server side | ||
- Injects `$get`,`$post`,... into vue context instances so requests can be done easily. | ||
- Exposes `setToken` function to `$axios` so we can easily and globally set authentication tokens. | ||
@@ -23,3 +22,3 @@ - Throws *nuxt-friendly* errors and optionally redirect on specific error codes. | ||
'@nuxtjs/axios', | ||
// With options | ||
@@ -48,26 +47,2 @@ ['@nuxtjs/axios', { credentials: false }], | ||
### Component mixins | ||
You can always access axios instance using `this.$axios`. | ||
This mixins are available for easier usage: | ||
- `$request` | ||
```js | ||
this.$request({url: 'http://example.com') | ||
``` | ||
- `$get`, `$delete`, `$head` | ||
```js | ||
this.$get('http://example.com') | ||
``` | ||
- `$post`, `$put`, `$patch` | ||
```js | ||
this.$post('http://example.com', { foo: 'bar' }) | ||
```` | ||
Example: | ||
```js | ||
async mounted() { | ||
const {data} = await this.$get('http://icanhazip.com') | ||
this.ip = data | ||
} | ||
``` | ||
### Store `nuxtServerInit` | ||
@@ -90,3 +65,3 @@ ```js | ||
this.$store.dispatch('getIP', { $axios: this.$axios }) | ||
} | ||
} | ||
} | ||
@@ -115,3 +90,3 @@ } | ||
### `browserBaseURL` | ||
### `browserBaseURL` | ||
- Default: `/api` | ||
@@ -130,3 +105,3 @@ | ||
Adds an interceptor to automatically set `withCredentials` config of axios when requesting to `baseUrl` | ||
which allows passing authentication headers to backend. | ||
which allows passing authentication headers to backend. | ||
@@ -170,3 +145,3 @@ ### `debug` | ||
- Defaults to `common` meaning all types of requests | ||
- Can be `get`, `post`, `delete`, ... | ||
- Can be `get`, `post`, `delete`, ... | ||
@@ -185,3 +160,3 @@ ```js | ||
this.$axios.setHeader('Content-Type', false, ['post']) | ||
``` | ||
``` | ||
### `setToken(token, type, scopes='common')` | ||
@@ -196,3 +171,3 @@ Axios instance has an additional helper to easily set global authentication header. | ||
- Defaults to `common` meaning all types of requests | ||
- Can be `get`, `post`, `delete`, ... | ||
- Can be `get`, `post`, `delete`, ... | ||
@@ -214,3 +189,3 @@ ```js | ||
this.$axios.setToken(false) | ||
``` | ||
``` | ||
@@ -226,3 +201,3 @@ ## Dynamic API Backend | ||
modules: [ | ||
'@nuxtjs/axios', | ||
'@nuxtjs/axios', | ||
'@nuxtjs/proxy' | ||
@@ -256,8 +231,8 @@ ], | ||
Details | ||
- `'@nuxtjs/axios'` | ||
- `'@nuxtjs/axios'` | ||
- By default axios plugin sets base url to `http://[host]:[port]/api` which is `http://localhost:3000/api` | ||
- `'/api': 'http://www.mocky.io/v2'` | ||
- `'/api': 'http://www.mocky.io/v2'` | ||
- This line creates a server middleware to pass requests from `/api` to `http://www.mocky.io/v2` | ||
- We used `pathRewrite` to remove `/api` from starting of requests and change it to `/v2` | ||
- For more information and advanced usage please refer to [proxy](../proxy) docs. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
19410
183
227