var ios = window.__wxjs_is_wkwebview;
if(ios){//判断是否是ios
that.iosPreview(localIds);
}else {
localIds.forEach(item => {
that.imgList.push(item);
})
}
2.采用异步请求的方式,在methods里面定义:
async iosPreview(localIds){
for(var i = 0; i < localIds.length; i++) {
await this.readImage(localIds[i]);
}
},
readImage(item){
let _this = this;
return new Promise((resolve, reject) => {
wx.getLocalImgData({
localId: item,
success: function(res) {
let localData = res.localData;
localData = localData.replace('jgp', 'jpeg');
_this.imgList.push(localData);
resolve('done!');
},
fail: function() {
}
})
})
}
二、安卓设备:
if(ios){//判断是否是ios
that.iosPreview(localIds);
}else {
that.androidPreview(localIds);
}
//方法
async androidPreview(localIds){
for(var i = 0; i < localIds.length; i++) {
await this.getImage(localIds[i]);
}
},
getImage(item){
let _this = this;
_this.imgList.push(item);
return new Promise((resolve, reject) => {
wx.getLocalImgData({
localId: item,
success: function(res) {
let localData = res.localData;
var imgBase64=localData.substring(localData.indexOf(",") + 1);
_this.phoneArr +=imgBase64+ ",";
resolve('done!');
_this.uploadImg(item);
},
fail: function() {
}
})
})
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)