uni.addInterceptor(name, interceptor)
添加拦截器
Parameters
name | type | required | default | description |
name | string | YES | - | 需要拦截的 API 名称 |
interceptor | Interceptor | YES | - | 拦截器 |
Interceptor Values
name | type | optinal | default | description |
invoke | (...args?: any) => any | NO | - | 拦截前触发 |
returnValue | (...args?: any) => any | NO | - | 方法调用后触发,处理返回值 |
success | (...args?: any) => any | NO | - | 成功回调拦截 |
fail | (...args?: any) => any | NO | - | 失败回调拦截 |
complete | (...args?: any) => any | NO | - | 完成回调拦截 |
addInterceptor Compatibility
Android version | Android uni-app | Android uni-app-x | iOS version | iOS uni-app | iOS uni-app-x |
5.0 | √ | 3.97 | 10.0 | √ | x |
See also
Related Bug
uni.removeInterceptor(name, interceptor?)
删除拦截器
Parameters
name | type | required | default | description |
name | string | YES | - | 需要删除拦截器的 API 名称 |
interceptor | Interceptor | NO | - | 拦截器 |
Interceptor Values
name | type | optinal | default | description |
invoke | (...args?: any) => any | NO | - | 拦截前触发 |
returnValue | (...args?: any) => any | NO | - | 方法调用后触发,处理返回值 |
success | (...args?: any) => any | NO | - | 成功回调拦截 |
fail | (...args?: any) => any | NO | - | 失败回调拦截 |
complete | (...args?: any) => any | NO | - | 完成回调拦截 |
removeInterceptor Compatibility
Android version | Android uni-app | Android uni-app-x | iOS version | iOS uni-app | iOS uni-app-x |
5.0 | √ | 3.97 | 10.0 | √ | x |
See also
Related Bug
Example
hello uni-app x
General type
GeneralCallbackResult
name | type | optinal | default | description |
errMsg | string | YES | - | 错误信息 |
Tips
- 目前仅以下接口支持拦截器:navigateTo、redirectTo、reLaunch、switchTab、navigateBack、loadFontFace、pageScrollTo、startPullDownRefresh、setNavigationBarColor、setNavigationBarTitle、setTabBarBadge、removeTabBarBadge、setTabBarItem、setTabBarStyle、hideTabBar、showTabBar、showTabBarRedDot、hideTabBarRedDot
- 如需拦截request,可在插件市场搜索拦截器插件