@itning/axios-helper
v1.1.2
Published
This lib will help you better use axios
Downloads
14
Readme
Axios Helper Lib
- 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(() => {
});