![GitHub followers](https://camo.githubusercontent.com/1cb90dfa92c8b1e863a55d53403320450e068c0cd202cd6cc487242059175af3/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f666f6c6c6f776572732f69746e696e672e7376673f7374796c653d736f6369616c266c6162656c3d466f6c6c6f77)
![language](https://camo.githubusercontent.com/04751046a540685358af79a8f0e7f323dc240631d8356413a5cc4c253aaae657/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c616e67756167652d547970655363726970742d677265656e2e737667)
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(() => {
});