Appearance
统一请求 - request
简介
- 用于数据接口请求
- 可通过配置,开启
服务监控平台对接口请求的监控 - 该API是一个异步任务,可使用async await / promise结构 获取回调值;
环境适配说明
| 环境名称 | 是否支持 | jssdk文件最低版本号 | npm包最低版本号 |
|---|---|---|---|
| 湘易办APP-小程序 | ✅ | 1.1.4 | 0.0.4 |
| 湘易办APP-小程序-webview | ✅ | 1.1.8 | 0.0.4 |
| 湘易办APP-webview | ✅ | 2.0.0 | 0.0.4 |
| 三方H5 | ✅ | 2.0.0 | 0.0.4 |
| 三方小程序 | ❌ | -- | 不支持 |
参数
| 参数名 | 类型 | 必填 | 描述 |
|---|---|---|---|
| url | String | ✅ | 请求地址 |
| method | String | ✅ | 请求类型 |
| data | String | ❌ | 请求body |
| headers | String | ❌ | 请求头 |
| timeout | Number | ❌ | 请求超时时长 |
返回值
与正常
xhr请求一致
示例
javascript
try {
const res = await this.$xybAgent.request({
url: 'https://api.github.com/users/xyb-agent',
method: 'GET',
timeout: 5000,
headers: {
'Content-Type': 'application/json'
},
data: {
name: 'xyb-agent'
}
});
if (res) {
// 执行业务处理
}
} catch (e) {
// 异常处理
}javascript
this.$xybAgent.request({
url: 'https://api.github.com/users/xyb-agent',
method: 'GET',
timeout: 5000,
headers: {
'Content-Type': 'application/json'
}
}).then(res => {
if (res) {
// 执行业务处理
}
}).catch(e => {
// 执行异常处理
})