- uni.chooseImage 在手机浏览器中无法在异步回调中拉起;
- 可以在异步完成后调用uni.showModal 然后在showModal的success回调中再去调用uni.chooseImage可以拉起成功。
chooseImage: async function() {
let that = this;
if (this.imageList.length === 3) {
let isContinue = await this.isFullImg();
if (!isContinue) {
return;
}
}
uni.chooseImage({
sourceType: sourceType[that.sourceTypeIndex],
sizeType: sizeType[that.sizeTypeIndex],
count: that.imageList.length + that.count[that.countIndex] > 3 ? 3 - that.imageList.length : that.count[that.countIndex],
success: (res) => {
that.imageList = that.imageList.concat(res.tempFilePaths);
},
fail: (err) => {
}
})
},
isFullImg: function() {
let that = this;
return new Promise((res) => {
setTimeout(function() {
//如果我把uni.showModal这段代码注释掉替换成 res(true); ,uni.chooseImage 就不会在手机端的浏览器中调起来
uni.showModal({
content: "已经有3张图片了,是否清空现有图片?",
success: (e) => {
if (e.confirm) {
that.imageList = [];
res(true);
} else {
res(false)
}
},
fail: () => {
res(false)
}
})
},2000)
})
}
2 个评论
要回复文章请先登录或注册
jayZ
4***@qq.com