小程序單張uni-app圖片預覽
uni.previewImage({
current:0,
urls: [mess.honorIcon],//['你的圖片地址']
});
小程序多張圖片預覽
<view class="img-boix-view">
<image class="limit-size" :src="imgcont.key" @tap="screenallView(allimgArr,imgindex)"
v-for="(imgcont,imgindex) in allimgArr" :key="imgindex">
</image>
</view>
screenallView(imgcont, index){
uni.previewImage({
current:index,
urls: imgcont.map(v=>v.key),//['你的圖片地址']
});
},
使用uni.previewImage需要注意的問題
uni.previewImage在在關閉的時候,會去調用onshow(){}這個生命周期
所以如果onshow中有接口調用的時候,需要注意一下;是否會產生數據的堆疊
noexebshowFalg:true, //控制是否會觸發生命周期
onShow() {
if(this.noexebshowFalg){
this.classTeacherSubjectList_api();
}
},
// 全屏
screenallView(imgcont, index){
this.noexebshowFalg=false;//不允許再次觸發onshow這個聲明周期
uni.previewImage({
current:index,
urls: imgcont.map(v=>v.key),//['你的圖片地址']
});
},
