执行多个并发请求:
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>
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/128133.html