🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

uve-request

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

uve-request

基于 axios 封装的请求库

npmnpm
Version
1.1.25
Version published
Weekly downloads
5
400%
Maintainers
1
Weekly downloads
 
Created
Source

uve-request

uve-request 是一个基于 axios 封装的高性能、多功能请求库,专为现代前端开发设计。它集成了加密、自动 Loading 管理、浙里办 (ZLB) 适配、Vue 插件支持等常用功能。

特性

  • 🚀 基于 Axios: 继承了 Axios 的所有优秀特性。
  • 🔐 安全性: 内置 SM4 (国密)、AES、SHA256 等多种加密方式。
  • 📦 单文件打包: 采用 Vite 进行库模式打包,提供 ESM 和 UMD 格式。
  • 🛠️ 浙里办适配: 内置 mgop 适配,支持 IRS 加密转发。
  • 🔄 自动 Loading: 配合 Store 自动管理请求状态。
  • 📥 实用工具: 内置文件下载、Blob 转换、参数序列化等工具。
  • 🔌 Vue 插件: 支持 Vue 3 插件式安装,无缝集成到全局属性。

安装

npm install uve-request
# 或者
yarn add uve-request

快速上手

基础用法

import request from 'uve-request';

// 发送一个 GET 请求
request.get('/api/user', { id: 1 }).then(res => {
  console.log(res);
});

// 发送一个 POST 请求
request({
  url: '/api/update',
  method: 'post',
  data: { name: 'Antigravity' }
}).then(res => {
  console.log(res);
});

在 Vue 3 中使用

import { createApp } from 'vue';
import request from 'uve-request';
import App from './App.vue';

const app = createApp(App);

app.use(request, {
  baseURL: 'https://api.example.com',
  tokenField: 'Authorization',
  successCode: [200, 2000],
  // 其他配置...
});

app.mount('#app');

// 在组件中通过 proxy 访问
// proxy.axios.get(...)

全局配置 (Options)

属性类型默认值说明
baseURLstring""基础 URL
useStore() => Storenull返回一个包含 token 和 requests(Set) 的对象,用于状态管理
successCodenumber[][200, 2000]业务成功的状态码
codeFieldstring | string[]"code"业务状态码字段名
messageFieldstring | string[]["errorMsg", "msg", "message"]错误信息字段名
tokenFieldstring"Authorization"请求头中 Token 的字段名
timeoutnumber-请求超时时间
onlySm4booleanfalse是否仅使用 SM4 加密(不进行 base64)

加密功能

SM4 加密

支持配置全局或单个请求的 SM4 加密。

request({
  url: '/api/secure',
  sm4Key: 'your-secret-key',
  encryptKey: 'data', // 需要加密的字段
  data: {
    data: 'sensitive info'
  }
});

AES 加密

通过 aesKey 和配置中的 aesStr 实现。

浙里办 (ZLB) 支持

当设置了 zlbApi 且配置了 zlbAppKey 时,库会自动切换到 mgop 适配器。

request({
  url: 'irs-api-path',
  zlbApi: 'mgop.xxxx.yyyy',
  method: 'post',
  data: { ... }
});

实用工具

  • download(data, filename, isLink): 通用下载方法。
  • requestAll(promises, setLoading): 合并多个请求,统一管理 Loading。
  • cancelAll(promises, message): 批量取消请求。
  • transParams(params): 将对象转为 URL 查询字符串。

许可证

MIT

FAQs

Package last updated on 12 Jan 2026

Did you know?

Socket

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.

Install

Related posts