@@ -8,6 +8,33 @@ import axios from 'axios';
88import ApiForm from './mixins/ApiForm' ;
99import ApiList from './mixins/ApiList' ;
1010
11+ function addInterceptors ( interceptors , api ) {
12+ const {
13+ requests : requestInterceptors ,
14+ responses : responseInterceptors ,
15+ } = interceptors ;
16+ if ( requestInterceptors ) {
17+ requestInterceptors . forEach ( ( interceptor ) => {
18+ if ( Array . isArray ( interceptor ) ) {
19+ api . interceptors . request . use ( ...interceptor ) ;
20+ } else {
21+ const { fulfilled, rejected } = interceptor ;
22+ api . interceptors . request . use ( fulfilled , rejected ) ;
23+ }
24+ } ) ;
25+ }
26+ if ( responseInterceptors ) {
27+ responseInterceptors . forEach ( ( interceptor ) => {
28+ if ( Array . isArray ( interceptor ) ) {
29+ api . interceptors . response . use ( ...interceptor ) ;
30+ } else {
31+ const { fulfilled, rejected } = interceptor ;
32+ api . interceptors . response . use ( fulfilled , rejected ) ;
33+ }
34+ } ) ;
35+ }
36+ }
37+
1138const VueRest = {
1239 install ( Vue , options ) {
1340 if ( Vue . vueRestInstalled ) {
@@ -20,30 +47,7 @@ const VueRest = {
2047 if ( options && options . axiosOptions ) {
2148 api = axios . create ( options . axiosOptions ) ;
2249 if ( options . interceptors ) {
23- const {
24- requests : requestInterceptors ,
25- responses : responseInterceptors ,
26- } = options . interceptors ;
27- if ( requestInterceptors ) {
28- requestInterceptors . forEach ( ( interceptor ) => {
29- if ( Array . isArray ( interceptor ) ) {
30- api . interceptors . request . use ( ...interceptor ) ;
31- } else {
32- const { fulfilled, rejected } = interceptor ;
33- api . interceptors . request . use ( fulfilled , rejected ) ;
34- }
35- } ) ;
36- }
37- if ( responseInterceptors ) {
38- responseInterceptors . forEach ( ( interceptor ) => {
39- if ( Array . isArray ( interceptor ) ) {
40- api . interceptors . response . use ( ...interceptor ) ;
41- } else {
42- const { fulfilled, rejected } = interceptor ;
43- api . interceptors . response . use ( fulfilled , rejected ) ;
44- }
45- } ) ;
46- }
50+ addInterceptors ( options . interceptors , api ) ;
4751 }
4852 if ( options . axiosOptions . localStorageAuthorization ) {
4953 const localStorageAuthorization =
0 commit comments