千峰商城-springboot项目搭建-41-axios异步请求方法

axios提供了多种异步请求方法,实现对RESTful风格的支持。

 

1.get请求

axios.get(url).then(function);
axios.get(url,{}).thrn(function);
 
复制代码
//使用axios的get请求传递参数,需要将参数设置在params下
axios.get("http://localhost:9999/music/detail",{
  params:{
    id:"28059417"
    }
  })
  .then(function(res){ console.log(res); });
复制代码

 

 

2.post请求

axios.post(url,{}).thrn(function);
axios.post("http://localhost:9999/music/search",{s:"张杰"})
.then(function(res){
    console.log(res);
});

 

 

 3.自定义请求:自定义请方式、请求参数、请求头、请求体(仅限于post)

复制代码
axios({
    url:"http://localhost:9999/music/search",
    method:"post",
    params:{
        //设置请求行传值
        s:"成都",
        limit:15
    },
    headers:{
        //设置请求头
        
    },
    data:{
        //设置请求体(仅限于post/put)
        
    }
}).then(function(res){
    //回调
    console.log(res);
});
复制代码

 

 

 

 

 
posted @   临易  阅读(59)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· PowerShell开发游戏 · 打蜜蜂
· 在鹅厂做java开发是什么体验
· 百万级群聊的设计实践
· WPF到Web的无缝过渡:英雄联盟客户端的OpenSilver迁移实战
· 永远不要相信用户的输入:从 SQL 注入攻防看输入验证的重要性
点击右上角即可分享
微信分享提示