var Ajax1 = new Promise((resolve, reject) => {
$.ajax({
url:this.GLOBAL.url + "schedules/web/vessel/detail?mmsi=" + this.mmsi,
type: "GET",
headers: {
Authorization: this.getToken()
},
beforeSend: function() {},
success: function(data) {
if (data.status == 1) {
resolve(data) //导出去的数据
}else{
reject(data)
}
},
error: function(e) {reject(data)}
})
})
var Ajax2 = new Promise((resolve, reject) => {
$.ajax({
url:this.GLOBAL.url + "schedules/web/vessel/track?mmsi=" + this.mmsi,
type: "GET",
headers: {
Authorization: this.getToken()
},
beforeSend: function() {},
success: function(data) {
if (data.status == 1) {
resolve(data) //导出去的数据
}else{reject(data)}
},
error: function(e) {reject(data)}
})
})
Promise.all([Ajax1,Ajax2]).then(res => {
//接口都返回
//此处 res 为接口 resolve (返回的数据)
//返回格式为数组
//数组0的值为 Ajax1
//数组1的值为 Ajax2
console.log(res)
this.loading = false
},error => {
console.log(error)
})
Promise.all请求——接口数据都返回
最新推荐文章于 2024-09-13 16:22:29 发布