更新记录

1.0.4(2025-06-13) 下载此版本

修改文档

1.0.3(2025-06-13) 下载此版本

完善拦截器

1.0.2(2025-06-12) 下载此版本

基本功能实现:中断请求, 动态加载配置, 发送请求之前 , 发送请求之后, 请求完成

查看更多

平台兼容性

uni-app x

Chrome Safari Android iOS 鸿蒙 微信小程序
5.0 12

其他

多语言 暗黑模式 宽屏模式
× ×

u-req

开发文档

UTS 语法 UTS API插件 UTS uni-app兼容模式组件 UTS 标准模式组件 Hello UTS

使用方式

复制代码<script>
// index.uvue
    import { TreqSucc } from "@/uni_modules/u-req"
    import * as API from "@/client/api.uts"
    export default {
        methods: {
            test() {
                API.login({ mobile: 2345, sms_code: "1368" }).then((res : TreqSucc) => {
                    console.log(res.data);
                    return res;
                })
            }
        }
    }
</script>

注册你的接口

复制代码// api.uts
import { merge, TreqSend } from "@/uni_modules/u-req"
import api from "./client.uts"

const baseUrl = "https://xxx.top"
const h5 = (url : string, op ?: UTSJSONObject) : TreqSend => api(merge({ url: `${baseUrl}/h5/${url}`, method: 'POST' }, op))

// export const login = h5("login", { token: false })
export const login = h5("login", null)

自定义你的拦截器

复制代码// client.uts
import { Api, Tconfig, TreqSucc } from "@/uni_modules/u-req"
export class Client extends Api {
    constructor() { super() }
    /** 发送请求之前
     * @param op 配置
     */
    protected override before(op : Tconfig) : Tconfig {
        // op.abort = true;
        return op
    }
    /** 发送请求之后
     * @param op 配置
     * @param abort 调用中断请求
     */
    protected override after(op : Tconfig, abort : () => void) {
        // op.abort = true;
        // abort()
    }
    /** 请求完成
     * @param op 配置
     * @param result 结果
     */
    protected override done(op : Tconfig, result : Promise<TreqSucc>) : Promise<TreqSucc> {
        return result.then((res : TreqSucc) : TreqSucc => {
            console.log("参数-:", op);
            console.log("结果-:", res.data);
            return res
        });
    }
}

export default new Client().api

隐私、权限声明

1. 本插件需要申请的系统权限列表:

2. 本插件采集的数据、发送的服务器地址、以及数据用途说明:

3. 本插件是否包含广告,如包含需详细说明广告表达方式、展示频率:

许可协议

MIT协议

暂无用户评论。

使用中有什么不明白的地方,就向插件作者提问吧~ 我要提问