https://github.com/itning/axios-helper
封装Axios库。This lib will help you better use axios
https://github.com/itning/axios-helper
axios helper typescript util
Last synced: about 1 year ago
JSON representation
封装Axios库。This lib will help you better use axios
- Host: GitHub
- URL: https://github.com/itning/axios-helper
- Owner: itning
- License: apache-2.0
- Created: 2020-03-05T05:31:01.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2024-08-04T10:45:00.000Z (almost 2 years ago)
- Last Synced: 2025-04-19T08:24:25.682Z (about 1 year ago)
- Topics: axios, helper, typescript, util
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/@itning/axios-helper
- Size: 617 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Axios Helper Lib
[](https://github.com/itning/axios-helper/stargazers)
[](https://github.com/itning/axios-helper/network/members)
[](https://github.com/itning/axios-helper/watchers)
[](https://github.com/itning?tab=followers)
[](https://github.com/itning/axios-helper/issues)
[](https://github.com/itning/axios-helper/blob/master/LICENSE)
[](https://github.com/itning/axios-helper/commits)
[](https://github.com/itning/axios-helper/releases)
[](https://badge.fury.io/js/%40itning%2Faxios-helper)
[](https://www.npmjs.com/package/@itning/axios-helper)
[](https://github.com/itning/axios-helper)
[](https://github.com/itning/axios-helper)
[](https://github.com/itning/axios-helper)
- How to use this lib ?
```shell
npm i @itning/axios-helper
```
```javascript
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(() => {
});
```