上传图片的时候,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)
}
谢谢@赵子龙
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)