Axios的get和post请求写法

执行get请求

 1 // 为给定 ID 的 user 创建请求
 2 axios.get('/user?ID=12345')
 3   .then(function (response) {
 4     console.log(response);
 5   })
 6   .catch(function (error) {
 7     console.log(error);
 8   });
 9 
10 // 可选地,上面的请求可以这样做
11 axios.get('/user', {
12     params: {
13       ID: 12345
14     }
15   })
16   .then(function (response) {
17     console.log(response);
18   })
19   .catch(function (error) {
20     console.log(error);
21   });

执行post

 1 axios.post('/user', {
 2     firstName: 'Fred',
 3     lastName: 'Flintstone'
 4   })
 5   .then(function (response) {
 6     console.log(response);
 7   })
 8   .catch(function (error) {
 9     console.log(error);
10   });

猜你喜欢

转载自www.cnblogs.com/yinhao-jack/p/10609421.html