一、get请求
1、接口参数为值
axios.get('http://127.0.0.1:8090/news/_id?' + id).then(res => {
// ... to do
}).catch(err => {
console.log(err)
})
2、接口参数为对象
let params = {Guid: 'xxx'};
axios.get('xxx?' + $.param(params)).then(res => {
// ... to do
}).catch(err => {
// ... to do
})
二、post请求
1、接口参数为对象集合
let model = [];
mode.push({
Guid: 'xxx'
});
axios.post('xxx', {list: model}).then(res => {
// ... to do
}).catch(err => {
// ... to do
})
2、接口单个参数
axios.post('xxx', {Guid: 'xx'}).then(res => {
// ... to do
}).catch(err => {
// ... to do
})

本文详细介绍了使用Axios库进行GET和POST请求的方法,包括如何传递接口参数,无论是作为值还是对象,以及如何处理请求的成功响应和错误。对于GET请求,展示了参数拼接和使用$.param的方式;对于POST请求,则解释了如何发送对象集合和单个参数。

被折叠的 条评论
为什么被折叠?



