mirror of
https://github.com/axios/axios.git
synced 2026-04-11 14:21:59 +08:00
chore(docs): fix documentation for usage of interceptors in axios (#6116)
chore(docs): fix documentation for usage of interceptors in axios (#6116)
This commit is contained in:
parent
45d0baa6b3
commit
8889dc0383
10
README.md
10
README.md
@ -719,8 +719,11 @@ instance.get('/longRequest', {
|
||||
You can intercept requests or responses before they are handled by `then` or `catch`.
|
||||
|
||||
```js
|
||||
|
||||
const instance = axios.create();
|
||||
|
||||
// Add a request interceptor
|
||||
axios.interceptors.request.use(function (config) {
|
||||
instance.interceptors.request.use(function (config) {
|
||||
// Do something before request is sent
|
||||
return config;
|
||||
}, function (error) {
|
||||
@ -729,7 +732,7 @@ axios.interceptors.request.use(function (config) {
|
||||
});
|
||||
|
||||
// Add a response interceptor
|
||||
axios.interceptors.response.use(function (response) {
|
||||
instance.interceptors.response.use(function (response) {
|
||||
// Any status code that lie within the range of 2xx cause this function to trigger
|
||||
// Do something with response data
|
||||
return response;
|
||||
@ -743,7 +746,8 @@ axios.interceptors.response.use(function (response) {
|
||||
If you need to remove an interceptor later you can.
|
||||
|
||||
```js
|
||||
const myInterceptor = axios.interceptors.request.use(function () {/*...*/});
|
||||
const instance = axios.create();
|
||||
const myInterceptor = instance.interceptors.request.use(function () {/*...*/});
|
||||
axios.interceptors.request.eject(myInterceptor);
|
||||
```
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user