前言:
很多时候,我们可能需要同时调用多个后台接口,就会高并发的问题,一般解决这个问题方法:
axios.all 和 axios.spread
***注意这里的$get是封装的axios方法,有兴趣的朋友请参考另一篇
//方法一:
searchTopic() {
return this.$axios({
url:'地址1',
method:'方式',//get/post/patch/put/deleted
params:{//参数get所以用params。post.put用data
}
})
}
//方法二:
searchs(){
return this.$axios({
url:'地址1',
method:'方式',//get/post/patch/put/deleted
params:{//参数get所以用params。post.put用data
}
})
},
axios.all([searchTopic(), searchs()])
.then(axios.spread(function (allSearchTopic, allSearchs) {
debugger//打印可以拿到所有的返回值
allSearchTopic == 方法一的返回值
allSearchs == 方法二的返回值
}));