首页 > 编程知识 正文

axios post和get区别,axios发送get请求

时间:2023-05-04 17:27:01 阅读:217419 作者:2169

不配置直接用简写的那种形式

执行get请求 axios.get('/user?ID=12345') .then(function (response) { console.log(response); }) .catch(function (error) { console.log(error); });

上面的请求也可以这样写

axios.get('/user', { params: { ID: 12345 } }) .then(function (response) { console.log(response); }) .catch(function (error) { console.log(error); }) 执行post请求 axios.post('/user', { firstName: 'Fred', lastName: 'Flintstone' }) .then(function (response) { console.log(response); }) .catch(function (error) { console.log(error); });

用配置的方法来写get和post请求

get请求 axios({ method: 'get', url: '/user/12345', params: { firstName: 'Fred', lastName: 'Flintstone' }});

2 post请求

axios({ method: 'post', url: '/user/12345', data: { firstName: 'Fred', lastName: 'Flintstone' }});

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。