//在methods中定义请求方法,并return出去,不要写请求回调then()
methods:{
getAllTask:function(){
console.log('调用第一个接口')
return this.$axios({
url:'http://192.168.*.**:***/api/getTask/getAllData',
method:'GET',
params:{
offset:1,
pageSize:10
}
})
},
getAllCity:function(){
console.log('调用第二个接口')
return this.$axios({
url:'http://192.168.*.**:***/city/getCities',
method:'GET',
})
}
},
//在mounted周期同时发送两个请求,并在请求都结束后,输出结果
mounted:function(){
var _this = this; //注意!一定要重新定义一下this指向
this.$axios.all([_this.getAllTask(),_this.getAllCity()])
.then(me.$axios.spread(function(res1, res2){
console.log('所有请求完成')
console.log('请求1结果',res1)
console.log('请求2结果',res2)
}))
} |