@@ -2,21 +2,21 @@ import axios from 'axios'
22import { stringify } from 'qs'
33const urlPrefix = '/api/'
44
5- const interceptors = ( ) => {
6- axios . interceptors . request . use ( ( config ) => {
7- return config
8- } , function ( error ) {
9- return Promise . reject ( error )
10- } )
5+ class API {
6+ constructor ( ) {
7+ axios . interceptors . request . use ( ( config ) => {
8+ return config
9+ } , function ( error ) {
10+ return Promise . reject ( error )
11+ } )
1112
12- axios . interceptors . response . use ( ( response ) => {
13- return response
14- } , ( error ) => {
15- return Promise . reject ( error )
16- } )
17- }
13+ axios . interceptors . response . use ( ( response ) => {
14+ return response
15+ } , ( error ) => {
16+ return Promise . reject ( error )
17+ } )
18+ }
1819
19- class API {
2020 /**
2121 * GET api
2222 * @param {String } getfix url head
@@ -25,7 +25,6 @@ class API {
2525 */
2626 getUrlData = ( getfix , data , callback , self ) => {
2727 const url = `${ urlPrefix } ${ getfix } ${ ( Object . keys ( data ) . length > 0 ? `?${ stringify ( data ) } ` : '' ) } `
28- interceptors ( )
2928 axios . get ( url )
3029 . then ( res => {
3130 callback ( res )
@@ -46,7 +45,6 @@ class API {
4645 */
4746 deleteUrlData = ( getfix , data , callback , self ) => {
4847 const url = `${ urlPrefix } ${ getfix } ${ ( Object . keys ( data ) . length > 0 ? `?${ stringify ( data ) } ` : '' ) } `
49- interceptors ( )
5048 axios . delete ( url )
5149 . then ( res => {
5250 callback ( res )
@@ -66,7 +64,6 @@ class API {
6664 * @param {Object } self this
6765 */
6866 postUrlData = ( postfix , data , callback , isJson , self ) => {
69- interceptors ( )
7067 axios . post ( `${ urlPrefix } ${ postfix } ` , isJson ? data : stringify ( data ) )
7168 . then ( res => {
7269 callback ( res )
@@ -87,7 +84,6 @@ class API {
8784 * @param {Object } self this
8885 */
8986 putUrlData = ( postfix , data , callback , isJson , self ) => {
90- interceptors ( )
9187 axios . put ( `${ urlPrefix } ${ postfix } ` , isJson ? data : stringify ( data ) )
9288 . then ( res => {
9389 callback ( res )
0 commit comments