for循环上传多张图片,filepath出错,求大神
发布于 5 年前 作者 mengping 14742 次浏览 来自 问答

上传图片的时候,filepath出现错误

var imgfiles = that.data.files;

var fileslength = that.data.files.length;

for (var i = 0; i < fileslength; i++) {

setTimeout(function () {

wx.uploadFile({

url: that.data.net + “user/AddImage/v1?u_openid=” + that.data.openid,

filePath:imgfiles[i],

name: ‘fileName’,

success: function (res) {

console.log(res);

var data = res.data

//do something

}

})

}, 100)

}

2 回复

谢谢@赵子龙

setTimeout去掉,要不就写个闭包,

setTimeout(function (i) {

return function(){

wx.uploadFile({

url: that.data.net + "user/AddImage/v1?u_openid=" + that.data.openid,

filePath:imgfiles[i],

name: 'fileName',

success: function (res) {

console.log(res);

var data = res.data

//do something

}

})

}

}(i), 100)

回到顶部