axios简单应用
2020-03-28 18:58
1056 查看
axios简单应用
Axios 是一个基于 promise 的 HTTP 库,可以用在浏览器和 node.js 中。
初始化HTML
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="author" content="avaos"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>axios使用</title> <style> #app { width: 400px; margin: 100px auto; text-align: center; } button:hover { cursor: pointer; } </style> </head> <body> <div id="app"> <button onclick="testGet()">Get请求</button> <button onclick="testPost()">Post请求</button> <button onclick="testPut()">Put请求</button> <button onclick="testDelete()">Delete请求</button> </div> </body> </html>
引入axios
<script src="https://cdn.bootcss.com/axios/0.19.2/axios.min.js"></script>
Get 请求
function testGet(){ console.log("get"); axios.get('http://localhost:3000/posts') .then(response=>{ console.log("/posts", response.data); } ); }
Post 请求
function testPost(){ console.log("post"); axios.post('http://localhost:3000/posts', {"title": "json-server2", "author": "typicode2" }) .then(response=>{ console.log("/posts", response.data); } ); }
Put 请求
function testPut(){ console.log("put"); axios.put('http://localhost:3000/posts/2', {"title": "json-server2...", "author": "typicode2.." }) .then(response=>{ console.log("/posts", response.data); } ); }
Delete 请求
function testDelete(){ console.log("delete"); axios.delete('http://localhost:3000/posts/2') .then(response=>{ console.log("/posts", response.data); } ); }
参考资料
- 点赞
- 收藏
- 分享
- 文章举报
相关文章推荐
- axios基本介绍和简单应用
- axios在vue中的应用(一)—— 简单调用
- 网络模块axios的简单应用
- 最实用axios简单教程应用示例
- 异步查询工具axios的简单应用
- Spring 注解学习手札(一) 构建简单Web应用
- vector的简单应用
- HTA的简单应用
- C++对fabs的简单应用
- div应用示例 --简单内容填充
- CSS滤镜简单应用
- 树状数组简单应用
- datagrid的一些简单应用
- 批处理的简单应用总结
- jquery.validate中文API和应用实例(二)简单验证-规则的应用
- 【C++】异常处理的简单应用。
- Android:使用fragment(碎片)—让你的应用更灵活(一)简单运用
- SSH的简单配置与应用
- unity 简单编辑器的扩展应用—1