uni-app 异步上传图片

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,

});

},

你可能感兴趣的:(小程序)