多张图片一起上传示例
发布于 6 年前 作者 fangpeng 6650 次浏览 来自 问答

官方能给个多张图片一次性上传示例吗

7 回复

15562888180

看蒙了  有整个示例的源码吗

如果你不需要对上传后对内容处理,只循环上传也是可以的

['img1', 'img2'].map(item => {
  wx.uploadFile({
    url: '',
    filePath: item,
    success: res => res.data
  })
})

咋写呀  初学  有示例吗

有什么不理解的?promise 内循环一个本地图片列表,然后返回 上传后的结果为一个 array

还不理解看下 promise 方法吧

https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Promise/all

Promise.all(['img1', 'img2'].map(item => wx.uploadFile({
  url: '',
  filePath: item,
  success: res => res.data
}))).then(res => {
  console.log(res)
})

写个 Promise 列队呗

回到顶部