跳到主要内容

网络

调用第三方网络请求

GET请求

this.$axios.get(url, config);

输入参数

参数类型必填含义
urlstring请求地址
configobject请求配置
paramsobject请求参数,用来帮url拼query
headersobject请求头信息

返回内容

返回一个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);

输入参数

参数类型必填含义
urlstring请求地址
dataobject请求参数
configobject请求配置
headersobject请求头信息

返回内容

返回一个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);

输入参数

参数类型必填含义
urlstring请求地址
configobject请求配置
paramsobject请求参数,用来帮url拼query
headersobject请求头信息

返回内容

返回一个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);

输入参数

参数类型必填含义
urlstring请求地址
dataobject请求参数
configobject请求配置
headersobject请求头信息

返回内容

返回一个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);

输入参数

参数类型必填含义
urlstring请求地址
fileobject上传文件
dataobject请求参数

返回内容

返回一个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网络请求的返回值