# sendNormalRequest
发送普通 HTTP 网络请求,支持 loading 控制
# 请求参数
| Prop | Type | Required | Default | Description |
|---|---|---|---|---|
options | Object | Y | {} | 请求参数,支持 weex stream.fetch 的所有参数 |
otherOptions | Object | N | {} | 额外选项 |
otherOptions.isShowLoading | Boolean | N | true | 是否显示 loading |
otherOptions.processCallback | Function | N | () => {} | 进度回调函数 |
# 参数代码示例
// 发送 GET 请求
const options = {
method: 'GET',
url: 'https://api.example.com/data',
headers: {
'Content-Type': 'application/json'
}
}
this.$bridge.sendNormalRequest(options).then(res => {
console.log('请求成功', res)
}).catch(err => {
console.log('请求失败', err)
})
// 发送 POST 请求,不显示 loading
const options = {
method: 'POST',
url: 'https://api.example.com/submit',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ key: 'value' })
}
const otherOptions = {
isShowLoading: false
}
this.$bridge.sendNormalRequest(options, otherOptions).then(res => {
console.log('请求成功', res)
})
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# 接口调用示例
this.$bridge
.sendNormalRequest(options, otherOptions)
.then(res => {
this.$alert(res)
})
.catch(err => {
this.$toast(err)
})
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
# 返回参数
| Prop | Type | Description |
|---|---|---|
data | Object | 请求成功时返回响应数据 |
# 返回示例
// 请求成功
{
"code": 0,
"msg": "success",
"data": {}
}
1
2
3
4
5
6
2
3
4
5
6