uni-app 异步上传图片
因为执行顺序的原因导致部分手机选中图片无法上传,或者上传完成拿不到返回值
async upload(){
const [err,{tempFilePaths}] = await uni.chooseImage({count: 9});
this.imgList = this.imgList.concat(tempFilePaths);
this.uploadTem(tempFilePaths);
},
async uploadTem(tempFilePaths) {
if(!tempFilePaths.length) {
return
}
const item = tempFilePaths.pop();
const res= await uni.uploadFile({
url: 'https://h5.grasslandfarming.com/api/imgupload',
filePath: item,
name: 'file',
});
const [err,{data}] = res;
this.uploadImg.push(JSON.parse(data).result);
this.uploadTem(tempFilePaths);
},
previewImage(index){
uni.previewImage({
urls: this.imgList,
current:index,
});
},