# uni.addInterceptor(name, interceptor)

添加拦截器

# 参数

名称 类型 必填 默认值 描述
name string - 需要拦截的 API 名称
interceptor Interceptor - 拦截器

# addInterceptor 兼容性

Android iOS web
3.97 4.11 4.0

# 参见

相关 Bug

# uni.removeInterceptor(name, interceptor?)

删除拦截器

# 参数

名称 类型 必填 默认值 描述
name string - 需要删除拦截器的 API 名称
interceptor Interceptor | null - 拦截器

# removeInterceptor 兼容性

Android iOS web
3.97 4.11 4.0

# 参见

相关 Bug

# 示例

hello uni-app x

Template

Script

<template>
  <view style="flex: 1;">
    <button @click="addInterceptor">添加路由拦截器</button>
    <button @click="removeInterceptor">移除路由拦截器</button>
    <text>点击下方按钮{{msg}}</text>
    <button @click="navigateTo">跳转到测试页面</button>
  </view>
</template>



<style>

</style>

# 通用类型

# GeneralCallbackResult

名称 类型 必备 默认值 描述
errMsg string - 错误信息

# Tips

  • 目前仅以下接口支持拦截器:navigateTo、redirectTo、reLaunch、switchTab、navigateBack、loadFontFace、pageScrollTo、startPullDownRefresh、setNavigationBarColor、setNavigationBarTitle、setTabBarBadge、removeTabBarBadge、setTabBarItem、setTabBarStyle、hideTabBar、showTabBar、showTabBarRedDot、hideTabBarRedDot
  • 如需拦截request,可在插件市场搜索拦截器插件