一、起步
// 写法1
axios({
method: 'get',
url: '',
params: {}
}).then(res => { do something });
// 写法2
axios.get('/user', {
params: {
ID: 12345
}
})
.then((res)=> {
console.log(res);
})
.catch((error)=> {
console.log(error);
});
//示例:
axios.get('/user?ID=12345')
.then((res)=> {
console.log(res);
})
.catch((error)=> {
console.log(error);
});
//简写:
axios.get(url, params).then(res => { do something })
axios.post('/user', {
firstName: 'Fred',
lastName: 'Flintstone'
})
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
});
网友评论