https://developers.weixin.qq.com/miniprogram/dev/extended/weui/uploader.html
//上传图片文件
uplaodFile(files) {
// 文件上传的函数,返回一个promise
return new Promise((resolve, reject) => {
var tempFilePaths = files.tempFilePaths;
//上传返回值
for (var i = 0; i < tempFilePaths.length; i++) {
wx.uploadFile({
url: app.globalData.urlCarPic,
filePath: tempFilePaths[i],
name: 'file',
success: function (res) {
var data = JSON.parse(res.data)
var urls = data.url
resolve({
urls
}),
reject(res)
},
fail: function (err) {
console.log(err)
}
})
}
})
},
uploadSuccess(e) {
var url = e.detail.urls
this.setData({
drivefiles: this.data.drivefiles.concat(url),
})
},
第一次就返回结果了,第二次就不执行了,学学js吧