プロジェクトに必要だったので、幸運なことに、それが「あなたの知らない JavaScript」に収録されていることを思い出しました。
Promise.all:
Promise.all([x,x,x,x]) x で表される他の Promise 操作、Ajax など、Promise でカプセル化されているものはすべて取り込むことができます。注: これらの Promise パラメータは、解決と拒否の解決を返す必要があります。もちろん、サードパーティのプラグインを使用している場合は、既にカプセル化された Promise がある可能性があるため、心配する必要はありません
。
Promise.all([this.getTimes(), this.getTime(), this.getRate()])
.then(res => {
let cumm = JSON.parse(localStorage.getItem('customT'))
if (cumm.type == 2) {
this.isBtn = true;
this.setSj(cumm.data)
} else {
this.isBtn = false;
}
}).catch(error => {
alert('获取数据失败')
})
return new Promise((resolve, reject) => {
var that = this;
$.ajax({
url: ipurl + '',
type: 'post',
dataType: "json",
success: function (res) {
resolve()
},
error: function () {
reject()
}
})
})