-
get请求
axios.get('/login?userId=111')
.then(res=>{
console.log(res);
}).catch(error=>{
console.log(error);
})
axios.get('/login',{
params:{
userId: 111
}
})
.then(res=>{
console.log(res);
}).catch(error=>{
console.log(error);
})
-
post请求
axios.post('/login',{
userId: 111,
userName: 'aa'
})
.then(res=>{
console.log(res);
}).catch(error=>{
console.log(error);
})
axios({
method:'post',
url:'/login',
data: {
userId: 111,
userName: 'aa'
}
})
axios的相关配置
{
url: '/login',
method: 'post',
baseURL: 'http://www.example.com',
headers: {'Authorization':'Bearer token'},
params: {userId: 111},
data: { userId: 111},
timeout: 1000,
transformRequest: [ function (data) {
return data;
}],
transformResponse: [ function (data) {
return data;
}]