handleClick1 (data) {
return this.$http({
method: 'post',
url: 'xxxxx',
data: data
})
},
handleClick2 (data) {
return this.$http({
method: 'post',
url: 'xxxxx',
data: data
})
},
handleClick3 (data) {
return this.$http({
method: 'post',
url: 'xxxxx',
data: data
})
}
// this.$http 就是axios的别名
// 在这里self 是this的一个别名
this.$http.all([
self.handleClick1(),
self.handleClick2(),
self.handleClick3()
]).then(this.$http.spread(function(res1, res2, res3){
console.log(res1, res2, res3);
// 这里拿到的res就是每个方法调用后的返回值
}))
同时执行多个请求,在成功回调里执行下一步显然行不通,为了防止方法之间的干扰,即使某个方法执行失败,也不会影响其他方法的执行,这个时候axios.all 方法就很好的解决了这个问题。