map 配合 Promis.all 循环上传图片

const banners = [ 'imgObj', 'imgObj', 'imgObj' ]

const bannersActions = _.map(banners, (item, index) => {
  return this.batchUpdateImg(item, index)
})

batchUpdateImg(obj, index) {
  return new Promise((resolve, reject) => {
      upload.upload(obj.file) .then(result => {
        resolve(result.url)
      }).catch(() => {
          reject(new Error(`${index}: failed to upload file`))
      })
   })
}

Promise.all(bannersActions).then(results => {
  console.log('>>>>>>>>', results.url)
})

你可能感兴趣的:(map 配合 Promis.all 循环上传图片)