找回密码
 立即注册
查看: 3|回复: 0

5,Axios对原生的Ajax进行了封装,简化书写,快速开发。

[复制链接]

261

主题

6

精华

265

金币

技术维护QQ:515138

积分
571
发表于 昨天 08:11 | 显示全部楼层 |阅读模式
介绍:Axios 对原生的Ajax进行了封装,简化书写,快速开发。
官网:https://www.axios-http.cn/
1.jpg 2.jpg
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4.     <meta charset="UTF-8">
  5.     <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6.     <title>Document</title>
  7. </head>
  8. <body>
  9.     <!-- 引入axios的js文件 -->
  10.     <s cript src="https://unpkg.com/axios/dist/axios.min.j s"></script>
  11.     <scri pt>
  12.         /* 发送请求 */
  13.         /* axios({
  14.             method:'get',
  15.             url:'http://localhost:8080/article/getAll'
  16.         }).then(result=>{
  17.             //成功的回调
  18.             //result代表服务器响应的所有的数据,包含了响应头,响应体. result.data 代表的是接口响应的核心数据
  19.             console.log(result.data);
  20.         }).catch(err=>{
  21.             //失败的回调
  22.             console.log(err);
  23.         }); */
  24.         let article = {
  25.             title: '明天会更好',
  26.             category: '生活',
  27.             time: '2000-01-01',
  28.             state: '草稿'
  29.         }
  30.         /*  axios({
  31.              method:'post',
  32.              url:'http://localhost:8080/article/add',
  33.              data:article
  34.          }).then(result=>{
  35.              //成功的回调
  36.              //result代表服务器响应的所有的数据,包含了响应头,响应体. result.data 代表的是接口响应的核心数据
  37.              console.log(result.data);
  38.          }).catch(err=>{
  39.              //失败的回调
  40.              console.log(err);
  41.          }); */
  42.         //别名的方式发送请求
  43.         /* axios.get('http://localhost:8080/article/getAll').then(result => {
  44.             //成功的回调
  45.             //result代表服务器响应的所有的数据,包含了响应头,响应体. result.data 代表的是接口响应的核心数据
  46.             console.log(result.data);
  47.         }).catch(err => {
  48.             //失败的回调
  49.             console.log(err);
  50.         }); */
  51.         axios.post('http://localhost:8080/article/add', article).then(result => {
  52.             //成功的回调
  53.             //result代表服务器响应的所有的数据,包含了响应头,响应体. result.data 代表的是接口响应的核心数据
  54.             console.log(result.data);
  55.         }).catch(err => {
  56.             //失败的回调
  57.             console.log(err);
  58.         });
  59.     </scrip t>
  60. </body>
  61. </html>
复制代码


3.jpg




上一篇:4,Vue生命周期
下一篇:6,VUE案例
网站建设,公众号小程序开发,系统定制,软件App开发,技术维护【联系我们】手机/微信:17817817816 QQ:515138

QQ|Archiver|自丢网 ( 粤ICP备2024252464号-1 )

GMT+8, 2026-3-6 05:36

专注于网站建设,公众号小程序制作,商城小程序,系统定制,软件App开发

【联系我们】手机/微信:17817817816 QQ:515138

快速回复 返回顶部 返回列表