千峰商城-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);
});
分类:
千峰商城项目
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· PowerShell开发游戏 · 打蜜蜂
· 在鹅厂做java开发是什么体验
· 百万级群聊的设计实践
· WPF到Web的无缝过渡:英雄联盟客户端的OpenSilver迁移实战
· 永远不要相信用户的输入:从 SQL 注入攻防看输入验证的重要性