
Research
Malicious npm Packages Impersonate Flashbots SDKs, Targeting Ethereum Wallet Credentials
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
axios-add-loading
Advanced tools
本库通过`axios`的[interceptors](https://github.com/axios/axios#interceptors)帮助你设置ajax请求中的loading
本库通过axios
的interceptors帮助你设置ajax请求中的loading
npm i -S axios-add-loading
createAddLoadingInterceptor(
axios: AxiosInstance,
options: AxiosAddLoadingOptions
)
axios
: axios实例options
: object类型参考参数说明import createAddLoadingInterceptor from 'axios-add-loading'
import axios from 'axios'
const instance = axios.create()
const options = {
showLoading: true,
delEmpty: true,
openLoading: () => { /* 打开loading方法 */},
closeLoading: () => { /* 关闭loading方法 */},
isResOk: res => { /* 对json进行过滤,返回boolean,满足条件的将会返回,参数为AxiosResponse.data */ },
onResNotOk: res => { /* 只有设置了isResOk才会生效,对不满足isResOk的请求,将会触发onResNotOk的回掉, 参数为 AxiosResponse.data*/ },
onResError: e => { /* ajax请求错误触发,如404,500等 */}
}
createAddLoadingInterceptor(instance, options)
instance({
method: 'get',
url: 'dir/xxx',
params: { foo: 'bar' },
// 这里可覆盖showLoading配置
showLoading: false,
// 这里可覆盖delEmpty配置
delEmpty: false,
})
是否删除 get
请求中 params 中为空的字段 xxx/dir?a=&b=3
=> xxx/dir?b=3
delEmpty: true
是否显示loading,需结合openLoading
和closeLoading
使用
showLoading: true
显示 loading 的方法, 拦截器发起请求前触发
openLoading: () => { /* 打开loading方法 */}
隐藏 loading 的方法, 拦截器完成请求触发
closeLoading: () => { /* 关闭loading方法 */}
大多数情况下response-schema只需要用到data,本方法主要过滤response-schema参数res为其中的data,定义规则确定那些返回内容是符合规则
的,如果未设置,拦截器将会返回response-schema
isResOk: res => res.code === 200
只有设置了 isResOk
才会生效,对不符合isResOk的请求进行处理
onResNotOk: res => {
if (res.code === 401) {
gotoLogin()
}
}
e为handling-errors, 对于请求异常的错误处理
onResError: e => {
if (e.response.status === 401) {
gotoLogin()
}
}
FAQs
本库通过`axios`的[interceptors](https://github.com/axios/axios#interceptors)帮助你设置ajax请求中的loading
The npm package axios-add-loading receives a total of 0 weekly downloads. As such, axios-add-loading popularity was classified as not popular.
We found that axios-add-loading demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
Security News
Ruby maintainers from Bundler and rbenv teams are building rv to bring Python uv's speed and unified tooling approach to Ruby development.
Security News
Following last week’s supply chain attack, Nx published findings on the GitHub Actions exploit and moved npm publishing to Trusted Publishers.