Axios 批量请求数据
mounted(){
var resData= this;
this.$axios.all([resData.baner1(),resData.baner2()])
this.$axios.all([resData.baner1((), resData.baner2()])
.then(this.$axios.spread(function (allBaner1, allBaner2 ) {
debugger
allBaner1== 方法一的返回值
allBaner2 == 方法二的返回值
}));
}
methods:{
baner1(){
console.log('调用第一个接口')
return this.Axios.post('/bannerApi1')
.then(res => {
const banner1 = res.data.banner1
this.banner1 = banner1
console.log(banner1)
});
},
baner2(){
console.log('调用第二个接口')
return this.Axios.post('/bannerApi2')
.then(res => {
const banner2 = res.data.banner2
this.banner2= banner2
console.log(banner2)
});
}
},