//图片上传
upload:function(filePath,index,length)
{
let that = this;
const cloudPath ="你要上传的文件路径"
wx.cloud.uploadFile({
cloudPath: cloudPath,
filePath:filePath[index],
success: res => {
console.log('[上传文件] 成功:', res.fileID)
},
fail: err => {
// handle error
console.log(err)
},
complete:function(e){
index++;
if(index==length)
{
console.log("上传完成")
}
else
{
that.upload(filePath,index,length);
}
}
})
},
本来用的是for循环来调用单张图片上传函数,在别人的指点之下改成了传入数组,直接上传。
此法在测试之下好像比循环上传要慢,有待考证。