美文网首页初见
map 配合 Promis.all 循环上传图片

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

作者: Cola丶ZYQ | 来源:发表于2019-08-15 15:10 被阅读0次
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 循环上传图片

    本文链接:https://www.haomeiwen.com/subject/msyzjctx.html