Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/lei1248276/uni-use-interceptor

uni-app 优化版 uni Interceptor
https://github.com/lei1248276/uni-use-interceptor

interceptor typescript uni-api uni-app

Last synced: 2 months ago
JSON representation

uni-app 优化版 uni Interceptor

Awesome Lists containing this project

README

        

# uni-use-interceptor
- 优化版 uni Interceptor,使用方式与"uni.addInterceptor"一致,不同点在于"uni.removeInterceptor"是移除指定API所有拦截器,该实现可以移除其中一个或所有。

## Install
```bash
pnpm add uni-use-interceptor
```
```bash
yarn add uni-use-interceptor
```
```bash
npm install uni-use-interceptor
```

## Usage
```typescript
import useInterceptor, { removeAllInterceptor } from 'uni-use-interceptor'
const stop = useInterceptor('request', {
invoke(args) {
args.url = 'https://www.example.com/' + args.url
}
})
// 移除指定拦截器
stop()
// 移除所有拦截器
removeAllInterceptor('request')
```