千峰商城-springboot项目搭建-42-axios并发请求
作者:互联网
执行多个并发请求:
axios.get(url1).then(function(res1){ //处理结果1 }); axios.get(url2).then(function(res2){ //处理结果2,不可写这里,可能因为网络影响,1还未执行完 }); //处理结果(需要等待两个请求都返回数据之后才执行)
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> <script type="text/javascript" src="js/vue.js" ></script> <script type="text/javascript" src="js/axios.min.js" ></script> </head> <body> <div id="container"> <button type="button" @click="test1">测试1</button> </div> <script type="text/javascript"> var vm = new Vue({ el:"#container", methods:{ test1:function(){ axios.all([listMusics(),getMusicDetail()]) .then(axios.spread(function// 两个请求现在都执行完成 console.log(res1); console.log(res2); })); } } }); functionreturn axios.get('http://localhost:9999/music/search?s=成都'functionreturn axios.get('http://localhost:9999/music/detail?id=25640392'); } </script> </body> </html>
标签:function,axios,springboot,get,42,9999,请求,处理结果 来源: https://www.cnblogs.com/lysboke/p/16468940.html