项目中往往会遇到上传多张图片,上传到服务器,下面就是我自己在项目中实现的上传多张图片
uni.chooseImage({
count: 9, //默认9
sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
sourceType: ['album'], //从相册选择
success: (file) => {
let img = file.tempFilePaths
for (let i = 0; i < img.length; i++) {
//这是封装的上传图片的接口
that.getUpfile('域名', img[i], 'file').then((res) => {
if(that.imageLists.length > 5){
//上传多张图片
that.imageLists.splice(0,1,`${that.url}${res.data}`);
}else{
that.imageLists.push(`${that.url}${res.data}`);
}
}, (res) => {
console.log(res)
})
}
}
});
如果有更好的方法 可以一起讨论