网络
调用第三方网络请求
GET请求
this.$axios.get(url, config);
输入参数
| 参数 | 类型 | 必填 | 含义 |
|---|---|---|---|
| url | string | 是 | 请求地址 |
| config | object | 否 | 请求配置 |
| params | object | 否 | 请求参数,用来帮url拼query |
| headers | object | 否 | 请求头信息 |
返回内容
返回一个Promise类型的对象,可以直接通过then来处理正确回调,通过catch来处理错误回调
示例
this.$axios.get('http://localhost:8080/user?ID=12345')
.then(function (response) {
// 请求成功的回调
console.log(response);
})
.catch(function (error) {
// 请求失败的回调
console.log(error);
});
POST请求
this.$axios.post(url, data, config);
输入参数
| 参数 | 类型 | 必填 | 含义 |
|---|---|---|---|
| url | string | 是 | 请求地址 |
| data | object | 否 | 请求参数 |
| config | object | 否 | 请求配置 |
| headers | object | 否 | 请求头信息 |
返回内容
返回一个Promise类型的对象,可以直接通过then来处理正确回调,通过catch来处理错误回调
示例
this.$axios.post('http://localhost:8080/user', {
firstName: 'Fred',
lastName: 'Flintstone'
})
.then(function (response) {
// 请求成功的回调
console.log(response);
})
.catch(function (error) {
// 请求失败的回调
console.log(error);
});
网络请求返回结构
{
// `data` 是服务器返回的网络响应
data: {},
// `status` 是服务器响应的 HTTP 状态代码
status: 200,
// `statusText` 是服务器响应的 HTTP 状态消息
statusText: 'OK',
// `headers` 是服务器响应的 HTTP 标头
// 所有标题名称都是小写的,可以使用括号表示法访问
// 例: `response.headers['content-type']`
headers: {},
// `request` 是生成此响应的请求
request: {}
}
| 字段 | 说明 |
|---|---|
| data | 服务器返回的网络响应数据 |
| status | 服务器响应的HTTP状态代码 |
| statusText | 服务器响应的HTTP状态消息 |
| headers | 服务器响应的HTTP标头(所有标题名称都是小写的) |
| request | 生成此响应的请求 |
调用平台网络请求
GET请求
this.$http.get(url, config);
输入参数
| 参数 | 类型 | 必填 | 含义 |
|---|---|---|---|
| url | string | 是 | 请求地址 |
| config | object | 否 | 请求配置 |
| params | object | 否 | 请求参数,用来帮url拼query |
| headers | object | 否 | 请求头信息 |
返回内容
返回一个Promise类型的对象,可以直接通过then来处理正确回调,通过catch来处理错误回调
示例
this.$http.get('api/User/GetUserInfo?UserId=xxx')
.then(function (response) {
// 请求成功的回调
console.log(response);
})
.catch(function (error) {
// 请求失败的回调
console.log(error);
});
POST请求
this.$http.post(url, data, config);
输入参数
| 参数 | 类型 | 必填 | 含义 |
|---|---|---|---|
| url | string | 是 | 请求地址 |
| data | object | 否 | 请求参数 |
| config | object | 否 | 请求配置 |
| headers | object | 否 | 请求头信息 |
返回内容
返回一个Promise类型的对象,可以直接通过then来处理正确回调,通过catch来处理错误回调
示例
this.$http.post('api/User/SaveUserInfo', {
firstName: 'Fred',
lastName: 'Flintstone'
})
.then(function (response) {
// 请求成功的回调
console.log(response);
})
.catch(function (error) {
// 请求失败的回调
console.log(error);
});
上传文件
this.$http.uploadFile(url, file, data);
输入参数
| 参数 | 类型 | 必填 | 含义 |
|---|---|---|---|
| url | string | 是 | 请求地址 |
| file | object | 否 | 上传文件 |
| data | object | 否 | 请求参数 |
返回内容
返回一个Promise类型的对象,可以直接通过then来处理正确回调,通过catch来处理错误回调
示例
this.$http.uploadFile(url, file, data)
.then(function (response) {
// 请求成功的回调
console.log(response);
})
.catch(function (error) {
// 请求失败的回调
console.log(error);
});
网络请求返回结构(平台)
{
"Code": 200,
"Status": 1,
"Message": "",
"Result": {}
}
| 字段 | 说明 |
|---|---|
| Code | 网络请求的返回码 |
| Status | 网络请求的返回状态 |
| Message | 网络请求的返回信息 |
| Result | 网络请求的返回值 |