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   });

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM