0%
前言
易用、简洁且高效的http库(中文官网)
引入
1
| <script src="js/axios.min.js"></script>
|
直接发送请求
发送Get请求
1 2 3 4 5 6 7 8
| axios({ method: "get", url: "http://example.com?key=value" }).then(function(result) { console.log(result); }).catch(function(error){ console.log(error); });
|
发送Post请求
1 2 3 4 5 6 7 8 9
| axios({ method: "post", url: "http://example.com", data: "key=value" }).then(function(result) { console.log(result); }).catch(function(error){ console.log(error); });
|
利用封装的函数发送请求
Get请求
1 2 3 4 5 6 7
| axios.get( "http://example.com?key=value" ).then(function(result){ console.log(result); }).catch(function(error){ console.log(error); });
|
Post请求
1 2 3 4 5 6 7 8 9 10
| axios.post( "http://example.com", { key: value } ).then(function(result){ console.log(result); }).catch(function(error){ console.log(error); });
|
完成
参考文献
官网中文文档
哔哩哔哩——黑马程序员