代码:
choice: function () {
var that = this
console.log(that.data.imgsrc.length);
if (that.data.imgsrc.length <= 3) {
var ino = 4 - that.data.imgsrc.length;
wx.chooseImage({
count: ino,
sizeType: ['compressed'],
sourceType: ['album', 'camera'],
success: (res) => {
var tempFilePaths = res.tempFilePaths
for (var item in res.tempFilePaths) {
console.log(res.tempFilePaths[item]);
that.data.imgsrc.push(res.tempFilePaths[item]);
tempFilePaths = that.data.imgsrc;
console.log(that.data.imgsrc);
}
let size = tempFilePaths.every(item => {
return item.size <= 2000000
})
if (size) {
that.setData({
imgsrc: tempFilePaths
})
}else{
wx.showToast({
title:'上传图片不能大于2M!',
icon:'none'
})
}
}
})
}
else {
wx.showToast({
title: "最多只能上传4张图片",
image: "/images/icon-warning.png",
});
}
},
|