getpushTotalCount() {
const platforms = ['youzy', 'youj', 'yousy', 'gaozy']
this.pushTotalCount = 0
for (let i = 0; i < platforms.length; i++) {
setTimeout(() => {
this.forgaozyCount(platforms[i])
})
}
},
async forgaozyCount(platform) {
this.totalCountQueryInput.platform = platform
const { isSuccess, result } = await forgaozyCount(this.totalCountQueryInput)
if (isSuccess) {
this.pushTotalCount += result.value
}
},
Promise.all 优化---------------------------
const platforms = ['youzy', 'youj', 'yousy', 'gaozy']
this.pushTotalCount = 0
const promises = platforms.map(platform => this.forgaozyCountV2(platform))
Promise.all(promises).then(() => {
this.pushButnDisabled = false
})
async forgaozyCountV2(platform) {
const input = { ...this.totalCountQueryInput, platform }
const { isSuccess, result } = await forgaozyCountV2(input)
if (isSuccess) {
this.pushTotalCount += result.value
}
},
入参不同,循环调用异步方法this.getpushTotalCount()
于 2024-05-23 09:48:45 首次发布