更新记录
1.0.0(2024-12-09) 下载此版本
✨ 特性
- 基于 uni.request 封装
- 轻量级请求插件
- 请求/响应拦截器
- Promise API支持
- 全局配置
- 多端兼容
平台兼容性
uni-app
| Vue2 | Vue3 | Chrome | Safari | app-vue | app-nvue | Android | iOS | 鸿蒙 |
|---|---|---|---|---|---|---|---|---|
| √ | √ | - | - | √ | √ | - | - | - |
| 微信小程序 | 支付宝小程序 | 抖音小程序 | 百度小程序 | 快手小程序 | 京东小程序 | 鸿蒙元服务 | QQ小程序 | 飞书小程序 | 快应用-华为 | 快应用-联盟 |
|---|---|---|---|---|---|---|---|---|---|---|
| - | - | - | - | - | - | - | - | - | - | - |
wht-request
基于 uni.request 封装的轻量级请求插件,支持拦截器、全局配置,多端兼容。
特性
- 基于 uni.request 封装
- 支持请求/响应拦截器
- 支持 Promise API
- 支持全局配置
- 多端兼容
安装
HBuilderX导入插件市场的wht-request插件。
使用
1. 全局配置
// main.js
import WhtRequestPlugin from '@/uni_modules/wht-request/js_sdk/install.js'
// Vue3
createApp().use(WhtRequestPlugin, {
baseURL: 'https://api.example.com'
})
// Vue2
Vue.use(WhtRequestPlugin, {
baseURL: 'https://api.example.com'
})
2. 发起请求
// 全局方式
this.$whtRequest.get('/users')
this.$whtRequest.post('/users', { name: 'John' })
// 或直接导入
import WhtRequest from '@/uni_modules/wht-request'
const request = WhtRequest.create({
baseURL: 'https://api.example.com'
})
request.get('/users')
request.post('/users', { name: 'John' })
3. 拦截器
request.addRequestInterceptor(
config => {
config.header.token = 'xxx'
return config
}
)
request.addResponseInterceptor(
response => response.data
)
配置项
| 参数 | 说明 | 默认值 |
|---|---|---|
| baseURL | 基础URL | '' |
| timeout | 超时(ms) | 60000 |
| header | 请求头 | {} |
以上配置项都会传递给底层的 uni.request。
支持平台
✅ H5、小程序、APP(基于uni.request,支持uni-app所有平台)
更新日志
查看 changelog.md

收藏人数:
https://gitee.com/funnywuss/uniapp-jssdks.git wht-request
下载插件并导入HBuilderX
下载插件ZIP
赞赏(0)
下载 1222
赞赏 11
下载 11676833
赞赏 1817
赞赏
京公网安备:11010802035340号