情景描述:当一次需要请求多个接口时,就可以使用axios.all();
因为重新封装了实例了axios所以,在实际调用的时候使用封装后的this.$axios.all()会报错的
所以需要重新引进一个axios实例
import axios from "axios";
axios.all([
this.$axios.post(this.$api.ExistNewAlarm),//这里是你请求的方法配置
this.$axios.post(this.$api.ExistNewFault),
this.$axios.post(this.$api.ExistNewGatewayOffline)
]).then(
axios.spread( (res1,res2,res3) => {
//这里是返回的数据
})
)
promise.all也可以并发请求 axios.all就是根据promise.all进行二次封装的
getBtnPermission() {
let p1 = Api.apiGetButtonPermission({ link: this.$route.matched[1].path })
let p2 = Api.apiGetButtonPermission({ link:'/article' })
Promise.all([p1,p2]).then(res=>{
console.log("res",res)
//这里打印出来的res就是请求的数据
})
},