8000 GitHub - itning/axios-helper: 封装Axios库。This lib will help you better use axios
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

itning/axios-helper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
8000  
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Axios Helper Lib

GitHub stars GitHub forks GitHub watchers GitHub followers

GitHub issues GitHub license GitHub last commit GitHub release npm version npm downloads GitHub repo size in bytes HitCount language

  • How to use this lib ?
npm i @itning/axios-helper
import {AxiosHelperConfig, Patch} from "@itning/axios-helper";
// Config message toast when net error.
AxiosHelperConfig.errorMsgImpl = {
    showErrorToast(title, data) {
        console.log(title + data.msg);
        setTimeout(() => {
            AxiosHelperConfig.onceMsgFinish();
            console.log('one message show finish')
        }, 2000);
    }
};
// Config interceptor for each request or response.
AxiosHelperConfig.axiosInstanceBuilder
    .requestInterceptor({
        onFulfilled: request => {

        },
        onRejected: error => {

        }
    })
    .responseInterceptor({
        onFulfilled: response => {

        },
        onRejected: error => {
            
        }
    })
    .build();
// You can use this api to send http patch request.
// Other http request
//Get("http://api.localhost.com")
//Delete("http://api.localhost.com")
//Post("http://api.localhost.com")
//Put("http://api.localhost.com")
Patch("http://api.localhost.com")
    // Config http success code,default 200.
    .withSuccessCode(200)
    // Config whether to open error message, defalut true.
    .withEnableErrorMsg(false)
    // Config error message title, defalut '错误'.
    .withErrorStartMsg("")
    // Invoke function when error happen.
    .withErrorHandle((error) => {

    })
    // Only show once msg
    .withOnceMsg()
    // Send http request with form data.
    .withFormData({"id": "1"})
    // Send http request with url search param data.
    .withURLSearchParams({})
    // Send http request with json data.	
    .withJson({1: 1})
    // When server response received will call this function.
    // Must call this function and will send http request.
    .do(response => {

    })
    // When do function invoked.
    .doAfter(() => {

    });
0